DropWhile

DropWhile ( callable $callback )

Discards input values while the callback function returns true, then all remaining values are returned. The first value returned is the one for which the callback function returned false.

Parameters

callback
bool callback ( mixed $value )
value
The current value.

Examples

Example #1

Basic usage example.

<?php
use Webbhuset\Pipeline\Constructor as F;

$dropWhile = F::DropWhile(function ($value) {
    return $value < 7;
});

$input = [1, 3, 5, 7, 9, 2, 4, 6, 8];

echo json_encode(iterator_to_array($dropWhile($input)));

// Output: [7,9,2,4,6,8]

See Also

  • Drop - Discard a specific amount of input values.
  • Filter - Discard input values based on a callback.
  • TakeWhile - Return input values while callback returns true.