src/fn/Map/Inner.php
private static function unify($inner)
    {
        if ($inner instanceof Iterator) {
            return $inner;
        }

        if (is_array($inner)) {
            return new RecursiveArrayIterator($inner);
        }

        $counter = 0;
        while ($inner instanceof IteratorAggregate) {
            $counter++ > 10 && fn\fail('$inner::getIterator is too deep');
            if (($temp = $inner->getIterator()) === $inner) {
                fn\fail('Implementation $inner::getIterator returns same instance');
            }
            $inner = $temp;
        }

        if ($inner instanceof Traversable && !$inner instanceof Iterator) {
            return $inner;
        }

        $inner instanceof Iterator || fn\fail('Property $inner must be iterable');
        return $inner;
    }
private static function unify($inner)
    {
        if ($inner instanceof Iterator) {
            return $inner;
        }

        if (is_array($inner)) {
            return new RecursiveArrayIterator($inner);
        }

        $counter = 0;
        while ($inner instanceof IteratorAggregate) {
            $counter++ > 10 && fn\fail('$inner::getIterator is too deep');
            if (($temp = $inner->getIterator()) === $inner) {
                fn\fail('Implementation $inner::getIterator returns same instance');
            }
            $inner = $temp;
        }

        if ($inner instanceof Traversable && !$inner instanceof Iterator) {
            return $inner;
        }

        $inner instanceof Iterator || fn\fail('Property $inner must be iterable');
        return $inner;
    }
@param traversable|array $inner

@return RecursiveArrayIterator|Traversable