| @@ 137-166 (lines=30) @@ | ||
| 134 | ->shouldReturn([2, 4, 4, 3]); |
|
| 135 | } |
|
| 136 | ||
| 137 | function it_can_reduce() |
|
| 138 | { |
|
| 139 | $this |
|
| 140 | ->reduce( |
|
| 141 | function ($temp, $item) { |
|
| 142 | return $temp + $item; |
|
| 143 | }, |
|
| 144 | 0 |
|
| 145 | ) |
|
| 146 | ->shouldReturn(9); |
|
| 147 | ||
| 148 | $this |
|
| 149 | ->reduce( |
|
| 150 | function ($temp, $item, $key) { |
|
| 151 | return $temp + $key + $item; |
|
| 152 | }, |
|
| 153 | 0 |
|
| 154 | ) |
|
| 155 | ->shouldReturn(15); |
|
| 156 | ||
| 157 | $this |
|
| 158 | ->reduce( |
|
| 159 | function (Collection $temp, $item) { |
|
| 160 | return $temp->append($item); |
|
| 161 | }, |
|
| 162 | new Collection([]) |
|
| 163 | ) |
|
| 164 | ->toArray() |
|
| 165 | ->shouldReturn([1, 3, 3, 2]); |
|
| 166 | } |
|
| 167 | ||
| 168 | function it_can_flatten() |
|
| 169 | { |
|
| @@ 431-460 (lines=30) @@ | ||
| 428 | $it->valid()->shouldReturn(false); |
|
| 429 | } |
|
| 430 | ||
| 431 | function it_can_reduce_from_right() |
|
| 432 | { |
|
| 433 | $this |
|
| 434 | ->reduceRight( |
|
| 435 | function ($temp, $e) { |
|
| 436 | return $temp . $e; |
|
| 437 | }, |
|
| 438 | 0 |
|
| 439 | ) |
|
| 440 | ->shouldReturn('02331'); |
|
| 441 | ||
| 442 | $this |
|
| 443 | ->reduceRight( |
|
| 444 | function ($temp, $key, $item) { |
|
| 445 | return $temp + $key + $item; |
|
| 446 | }, |
|
| 447 | 0 |
|
| 448 | ) |
|
| 449 | ->shouldReturn(15); |
|
| 450 | ||
| 451 | $this |
|
| 452 | ->reduceRight( |
|
| 453 | function (Collection $temp, $item) { |
|
| 454 | return $temp->append($item); |
|
| 455 | }, |
|
| 456 | new Collection([]) |
|
| 457 | ) |
|
| 458 | ->toArray() |
|
| 459 | ->shouldReturn([2, 3, 3, 1]); |
|
| 460 | } |
|
| 461 | ||
| 462 | function it_can_return_only_first_x_elements() |
|
| 463 | { |
|