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