$v) { $map->set($k, self::toCollection($v)); } return $map; } /** * Recursively transforms data into a list (on the first level, deeper levels * transformed to an appropriate collection) (experimental API) * * @param array|Iterator $collection * * @return ArrayList */ public static function toList(Iterator|array $collection): ArrayList { $list = new ArrayList(); /** @var mixed $v */ foreach ($collection as $v) { $list->add(self::toCollection($v)); } return $list; } /** * Recursively exports a collection to an array * * @param mixed $collection * * @return array * * @psalm-suppress MixedAssignment */ public static function toArrayRecursive(mixed $collection): array { $arr = $collection; if (is_object($collection) && method_exists($collection, 'toArray')) { $arr = $collection->toArray(); } /** @var array $arr */ return array_map( function (mixed $v): mixed { if (is_object($v) && method_exists($v, 'toArray')) { return static::toArrayRecursive($v); } return $v; }, $arr ); } }