-
-
Notifications
You must be signed in to change notification settings - Fork 13
IEnumerable.takeWhile() method
Marcel Kloubert edited this page Jun 26, 2021
·
5 revisions
Takes elements in that sequence as long as a specified condition is true (s. TakeWhile()).
public function takeWhile(predicate $predicate) : IEnumerable;
Name | Type | Description |
---|---|---|
$predicate | predicate | The condition to use. |
The condition to use.
The new sequence.
use \System\Linq\Enumerable;
$seq = Enumerable::create([239, 5979, 22, 1]);
foreach ($seq->takeWhile('$x => $x != 22') as $item) {
// [0] 239
// [1] 5979
}
use \System\Linq\Enumerable;
$seq = Enumerable::create([239, 5979, 22, 1]);
foreach ($seq->takeWhile(function ($x) {
return $x != 22;
}) as $item) {
// [0] 239
// [1] 5979
}