| @@ 46-54 (lines=9) @@ | ||
| 43 | /** |
|
| 44 | * @return string |
|
| 45 | */ |
|
| 46 | public static function reduce(\Traversable $iterator, callable $callback, $initial = null) |
|
| 47 | { |
|
| 48 | $callback = \Closure::fromCallable($callback); |
|
| 49 | iterator_apply( |
|
| 50 | $iterator, |
|
| 51 | function ($iterator) use (&$initial, $callback) { |
|
| 52 | $initial = $callback($initial, $iterator->current(), $iterator->key()); |
|
| 53 | return true; |
|
| 54 | }, |
|
| 55 | [$iterator] |
|
| 56 | ); |
|
| 57 | return $initial; |
|
| @@ 149-158 (lines=10) @@ | ||
| 146 | * @param \Iterator $input [description] |
|
| 147 | * @param callable $callback [description] |
|
| 148 | */ |
|
| 149 | public function process(\Iterator $input, callable $callback) |
|
| 150 | { |
|
| 151 | $callback = \Closure::fromCallable($callback); |
|
| 152 | $input->rewind(); |
|
| 153 | iterator_apply( |
|
| 154 | $input, |
|
| 155 | function (\Iterator $iterator) use ($callback) { |
|
| 156 | $callback($iterator->current(), $iterator->key(), $iterator, $this); |
|
| 157 | return true; |
|
| 158 | }, |
|
| 159 | [$input] |
|
| 160 | ); |
|
| 161 | return $this; |
|
| @@ 129-138 (lines=10) @@ | ||
| 126 | * @param callable $callback |
|
| 127 | * Callback for each item in iterator. |
|
| 128 | */ |
|
| 129 | public function process(\Iterator $input, callable $callback) |
|
| 130 | { |
|
| 131 | $callback = \Closure::fromCallable($callback); |
|
| 132 | $input->rewind(); |
|
| 133 | iterator_apply( |
|
| 134 | $input, |
|
| 135 | function (\Iterator $iterator) use ($callback) { |
|
| 136 | $callback($iterator->current(), $iterator->key(), $iterator, $this); |
|
| 137 | return true; |
|
| 138 | }, |
|
| 139 | [$input] |
|
| 140 | ); |
|
| 141 | return $this; |
|