-
-
Notifications
You must be signed in to change notification settings - Fork 13
IEnumerable.toSet() method
Marcel Kloubert edited this page Feb 22, 2015
·
1 revision
Returns a new set of that sequence.
public ISet toSet([callable $comparer = null]);
Name | Type | Description |
---|---|---|
$comparer | callable | [OPTIONAL] The custom item comparer to use. |
The new set.
use \System\Linq\Enumerable;
$seq = Enumerable::fromValues(1, 2, 3, 2);
$set = $seq->toSet();
foreach ($set as $item) {
// [0] 1
// [1] 2
// [2] 3
}
use \System\Linq\Enumerable;
$seq = Enumerable::fromValues(1, 2, 3, "2");
$set = $seq->toSet(function($x, $y) {
return $x === $y;
});
foreach ($set as $item) {
// [0] 1
// [1] 2
// [2] 3
// [3] '2'
}