diff --git a/src/Traits/CommonMutableContainerTrait.php b/src/Traits/CommonMutableContainerTrait.php index cd78e3e..d91647a 100644 --- a/src/Traits/CommonMutableContainerTrait.php +++ b/src/Traits/CommonMutableContainerTrait.php @@ -5,6 +5,7 @@ use Collections\ArrayList; use Collections\Dictionary; use Collections\Iterable; +use Collections\VectorInterface; trait CommonMutableContainerTrait { @@ -78,7 +79,8 @@ public function groupBy($callback) foreach ($this as $value) { $key = $callback($value); if (!$group->containsKey($key)) { - $group->add($key, new static([$value])); + $element = $this instanceof VectorInterface ? new static([$value]) : new ArrayList([$value]); + $group->add($key, $element); } else { $value = $group->get($key)->add($value); $group->set($key, $value);