-
-
Notifications
You must be signed in to change notification settings - Fork 13
IEnumerable.select() method
Marcel Kloubert edited this page Sep 25, 2015
·
2 revisions
Projects each element of that sequence to a new value (s. Select()).
public function select(callable $selector) : IEnumerable;
Name | Type | Description |
---|---|---|
$selector | [[callable | Callable]] |
A callable that transforms the current element to a new one.
function (mixed $item,
IIndexedItemContext $ctx) : mixed;
The current item.
The item context for $item
.
The new sequence.
use \System\Linq\Enumerable;
$seq = Enumerable::fromValues(239, 59.79, null);
// convert items to strings
foreach ($seq->select('$x => (string)$x') as $item) {
// [0] '239'
// [1] '59.79'
// [2] ''
}
use \System\Linq\Enumerable;
$seq = Enumerable::fromValues(239, 59.79, null);
// convert items to strings
foreach ($seq->select(function($x) {
return (string)$x;
}) as $item) {
// [0] '239'
// [1] '59.79'
// [2] ''
}