private function mapPairsBy($mapper, $mapType = 'mapBy') { return $this->asPairs()->{$mapType}($this->getCollectionCallbackFor($mapper))->foldBy(function ($builder, $pair) { if ($builder instanceof CollectionBuilder) { return $builder->add($pair); } // Is pair like? if (is_array($pair) && count($pair) == 2) { return $builder->put($pair[0], $pair[1]); } else { $collectionBuilder = new CollectionBuilder(); // Downgrade to collection... return $collectionBuilder->addAll($builder->build()->asPairs())->add($pair); } }, static::createMapBuilder(false))->build(); }
/** * @param array|\Traversable|mixed $data * * @return \Colada\Collection */ function to_collection($data) { $builder = new CollectionBuilder(); return $builder->addAll($data)->build(); }