Skip to content
This repository was archived by the owner on Dec 28, 2023. It is now read-only.

Commit 40e3f59

Browse files
committed
Fix lost values in Iterator which key is duplicated
1 parent da5746a commit 40e3f59

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/Enumerable.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ public function shuffle()
460460
{
461461
return $this->newLazyCollection(function() {
462462
$xs = $this->getSource();
463-
$array = Iterators::toArray($xs);
463+
$array = Iterators::toList($xs);
464464
shuffle($array);
465465
return $array;
466466
});
@@ -470,7 +470,7 @@ public function sample($n = null)
470470
{
471471
$xs = $this->getSource();
472472
if ($n === null) {
473-
$array = Iterators::toArray($xs);
473+
$array = Iterators::toList($xs);
474474
if (empty($array)) {
475475
return null;
476476
}
@@ -646,15 +646,15 @@ public function reverse()
646646
{
647647
return $this->newLazyCollection(function() {
648648
$xs = $this->getSource();
649-
return array_reverse(Iterators::toArray($xs));
649+
return array_reverse(Iterators::toList($xs));
650650
});
651651
}
652652

653653
public function sort($comparer = null)
654654
{
655655
$comparer = $this->resolveComparer($comparer);
656656
return $this->newLazyCollection(function() use ($comparer) {
657-
$xs = Iterators::toArray($this->getSource());
657+
$xs = Iterators::toList($this->getSource());
658658
usort($xs, $comparer);
659659
return $xs;
660660
});
@@ -693,7 +693,7 @@ public function object($values = null)
693693

694694
public function indexOf($value, $isSorted = 0)
695695
{
696-
$xs = Iterators::toArray($this->getSource());
696+
$xs = Iterators::toList($this->getSource());
697697

698698
if ($isSorted === true) {
699699
$i = $this->newCollection($xs)->sortedIndex($value);
@@ -713,7 +713,7 @@ public function indexOf($value, $isSorted = 0)
713713

714714
public function lastIndexOf($x, $fromIndex = null)
715715
{
716-
$xs = Iterators::toArray($this->getSource());
716+
$xs = Iterators::toList($this->getSource());
717717
$l = count($xs);
718718
$i = $fromIndex !== null ? min($l, $fromIndex) : $l;
719719

@@ -728,7 +728,7 @@ public function lastIndexOf($x, $fromIndex = null)
728728

729729
public function sortedIndex($value, $selector = null)
730730
{
731-
$xs = Iterators::toArray($this->getSource());
731+
$xs = Iterators::toList($this->getSource());
732732
$selector = $this->resolveSelector($selector);
733733
$value = $selector($value, null, []);
734734

tests/AbstractCollectionTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,6 +1094,10 @@ public function testFlatten($factory)
10941094
$result = $factory($list)->flatten(true)->toList();
10951095
$shouldBe = [1, 2, 3, [[[4]]]];
10961096
$this->assertSame($shouldBe, $result, 'can shallowly flatten nested arrays');
1097+
1098+
$result = $factory($list)->flatten()->reverse()->toList();
1099+
$shouldBe = [4, 3, 2, 1];
1100+
$this->assertSame($shouldBe, $result, 'can flatten nested arrays');
10971101
}
10981102

10991103
/**

0 commit comments

Comments
 (0)