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