| @@ 72-85 (lines=14) @@ | ||
| 69 | /** |
|
| 70 | * @inheritdoc |
|
| 71 | */ |
|
| 72 | public function first(callable $fn = null, $default = null) |
|
| 73 | { |
|
| 74 | if (is_null($fn)) { |
|
| 75 | return count($this->items) > 0 ? reset($this->items) : $default; |
|
| 76 | } |
|
| 77 | ||
| 78 | foreach ($this->getIterator() as $value) { |
|
| 79 | if (call_user_func($fn, $value)) { |
|
| 80 | return $value; |
|
| 81 | } |
|
| 82 | } |
|
| 83 | ||
| 84 | return $default; |
|
| 85 | } |
|
| 86 | ||
| 87 | /** |
|
| 88 | * @inheritdoc |
|
| @@ 90-103 (lines=14) @@ | ||
| 87 | /** |
|
| 88 | * @inheritdoc |
|
| 89 | */ |
|
| 90 | public function last(callable $fn = null, $default = null) |
|
| 91 | { |
|
| 92 | if (is_null($fn)) { |
|
| 93 | return count($this->items) > 0 ? end($this->items) : $default; |
|
| 94 | } |
|
| 95 | ||
| 96 | foreach (array_reverse($this->items) as $value) { |
|
| 97 | if (call_user_func($fn, $value)) { |
|
| 98 | return $value; |
|
| 99 | } |
|
| 100 | } |
|
| 101 | ||
| 102 | return $default; |
|
| 103 | } |
|
| 104 | } |
|
| 105 | ||