Skip to content

Commit

Permalink
feat: Added Set::values() method
Browse files Browse the repository at this point in the history
  • Loading branch information
rudashi committed Sep 26, 2024
1 parent 2de97b5 commit 7e206cf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/JavaScript/Set.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ public function toArray(): array
return $this->items;
}

/**
* Returns Set values as SetIterator.
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values
*
* @return \Rudashi\JavaScript\SetIterator<int, TValue>
*/
public function values(): SetIterator
{
return new SetIterator($this->items);
}

/**
* @param iterable<array-key, TValue> $items
*
Expand Down
24 changes: 24 additions & 0 deletions tests/Unit/SetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,30 @@
['bar', true],
]);

describe('values', function () {
it('returns new SetIterator', function () {
$set = new Set(['foo', 'bar']);

$newMap = $set->values();

expect($newMap)
->toBeInstanceOf(SetIterator::class)
->current()?->toBe('foo')
->next()?->toBe('bar');
});

it('returns values', function () {
$set = new Set(['foo' => 'bar', 'baz' => 'boo']);

$newMap = $set->values();

expect($newMap)
->toBeInstanceOf(SetIterator::class)
->current()?->toBe('bar')
->next()?->toBe('boo');
});
});

describe('magic methods', function () {
it('access a property', function () {
$set = new Set();
Expand Down

0 comments on commit 7e206cf

Please sign in to comment.