Skip to content

Commit e503936

Browse files
committed
Add map function implementation for Set
1 parent 7eea620 commit e503936

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Set.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,22 @@ public function last()
258258
return $this->table->last()->key;
259259
}
260260

261+
/**
262+
* Returns a new set using the results of applying a callback to each
263+
* value.
264+
*
265+
* @param callable $callback
266+
*
267+
* @return Set
268+
*
269+
* @template TNewValue
270+
* @psalm-param callable(TValue): TNewValue $callback
271+
* @psalm-return Set<TNewValue>
272+
*/
273+
public function map(callable $callback) {
274+
return new self(array_map($callback, $this->toArray()));
275+
}
276+
261277
/**
262278
* Iteratively reduces the set to a single value using a callback.
263279
*

0 commit comments

Comments
 (0)