diff --git a/src/Collections/Collection.php b/src/Collections/Collection.php index 972dcf1..509a167 100644 --- a/src/Collections/Collection.php +++ b/src/Collections/Collection.php @@ -48,12 +48,15 @@ class Collection extends ImmutableCollection implements ICollection { * @inheritDoc */ public function prependCollection (IImmutableCollection ...$collections): ICollection { - foreach ($collections as $collection) { - foreach ($collection as $value) { - $this->prepend($value); - } - } - return $this; + $prepend = array_merge( + ...array_map( + function (IImmutableCollection $collection): array { + return $collection->values()->toArray(); + }, + $collections + ) + ); + return $this->prepend(...$prepend); } /** diff --git a/tests/test_class.php b/tests/test_class.php index 48a2afd..77cbd71 100644 --- a/tests/test_class.php +++ b/tests/test_class.php @@ -23,9 +23,12 @@ class Measure { * @return Collection */ function getMeasures (): Collection { + $mesures_avant = new Collection(); + $mesures_avant->add(new Measure(38), new Measure(29)); + $measures = new Collection(); $measures->add(new Measure(27), new Measure(34)); - $measures->prepend(new Measure(38)); + $measures->prependCollection($mesures_avant); return $measures; }