@@ 70-79 (lines=10) @@ | ||
67 | /** |
|
68 | * @inheritDoc |
|
69 | */ |
|
70 | public function map(callable $callable) |
|
71 | { |
|
72 | $function = $this->normalizeAsCallables($callable); |
|
73 | $mapping = function ($iterator) use ($function) { |
|
74 | foreach ($iterator as $key => $item) { |
|
75 | yield $key => $function($item); |
|
76 | } |
|
77 | }; |
|
78 | return new static($mapping($this->getInnerIterator())); |
|
79 | } |
|
80 | ||
81 | /** |
|
82 | * @inheritDoc |
|
@@ 84-95 (lines=12) @@ | ||
81 | /** |
|
82 | * @inheritDoc |
|
83 | */ |
|
84 | public function filter(callable $callable) |
|
85 | { |
|
86 | $function = $this->normalizeAsCallables($callable); |
|
87 | $filter = function ($iterator) use ($function) { |
|
88 | foreach ($iterator as $key => $item) { |
|
89 | if ($function($item)) { |
|
90 | yield $item; |
|
91 | } |
|
92 | } |
|
93 | }; |
|
94 | return new static($filter($this->getInnerIterator())); |
|
95 | } |
|
96 | ||
97 | /** |
|
98 | * Alias for filter() |
|
@@ 112-123 (lines=12) @@ | ||
109 | /** |
|
110 | * @inheritDoc |
|
111 | */ |
|
112 | public function reject(callable $callable) |
|
113 | { |
|
114 | $function = $this->normalizeAsCallables($callable); |
|
115 | $rejection = function ($iterator) use ($function) { |
|
116 | foreach ($iterator as $key => $item) { |
|
117 | if (!$function($item)) { |
|
118 | yield $item; |
|
119 | } |
|
120 | } |
|
121 | }; |
|
122 | return new static($rejection($this->getInnerIterator())); |
|
123 | } |
|
124 | ||
125 | /** |
|
126 | * @inheritDoc |