| @@ 144-175 (lines=32) @@ | ||
| 141 | ->shouldReturn([2, 4, 4, 3]); |
|
| 142 | } |
|
| 143 | ||
| 144 | function it_can_reduce() |
|
| 145 | { |
|
| 146 | $this->beConstructedWith([1, 3, 3, 2,]); |
|
| 147 | ||
| 148 | $this |
|
| 149 | ->reduce( |
|
| 150 | function ($temp, $item) { |
|
| 151 | return $temp + $item; |
|
| 152 | }, |
|
| 153 | 0 |
|
| 154 | ) |
|
| 155 | ->shouldReturn(9); |
|
| 156 | ||
| 157 | $this |
|
| 158 | ->reduce( |
|
| 159 | function ($temp, $item, $key) { |
|
| 160 | return $temp + $key + $item; |
|
| 161 | }, |
|
| 162 | 0 |
|
| 163 | ) |
|
| 164 | ->shouldReturn(15); |
|
| 165 | ||
| 166 | $this |
|
| 167 | ->reduce( |
|
| 168 | function (Collection $temp, $item) { |
|
| 169 | return $temp->append($item); |
|
| 170 | }, |
|
| 171 | new Collection([]) |
|
| 172 | ) |
|
| 173 | ->toArray() |
|
| 174 | ->shouldReturn([1, 3, 3, 2]); |
|
| 175 | } |
|
| 176 | ||
| 177 | function it_can_flatten() |
|
| 178 | { |
|
| @@ 468-499 (lines=32) @@ | ||
| 465 | $collection->valid()->shouldReturn(false); |
|
| 466 | } |
|
| 467 | ||
| 468 | function it_can_reduce_from_right() |
|
| 469 | { |
|
| 470 | $this->beConstructedWith([1, 3, 3, 2,]); |
|
| 471 | ||
| 472 | $this |
|
| 473 | ->reduceRight( |
|
| 474 | function ($temp, $e) { |
|
| 475 | return $temp . $e; |
|
| 476 | }, |
|
| 477 | 0 |
|
| 478 | ) |
|
| 479 | ->shouldReturn('02331'); |
|
| 480 | ||
| 481 | $this |
|
| 482 | ->reduceRight( |
|
| 483 | function ($temp, $key, $item) { |
|
| 484 | return $temp + $key + $item; |
|
| 485 | }, |
|
| 486 | 0 |
|
| 487 | ) |
|
| 488 | ->shouldReturn(15); |
|
| 489 | ||
| 490 | $this |
|
| 491 | ->reduceRight( |
|
| 492 | function (Collection $temp, $item) { |
|
| 493 | return $temp->append($item); |
|
| 494 | }, |
|
| 495 | new Collection([]) |
|
| 496 | ) |
|
| 497 | ->toArray() |
|
| 498 | ->shouldReturn([2, 3, 3, 1]); |
|
| 499 | } |
|
| 500 | ||
| 501 | function it_can_return_only_first_x_elements() |
|
| 502 | { |
|