src/GeneratorCollection.php
public function flatten($depth = INF): CollectionInterface
    {
        return $this->wrap(function (Iterator $data) use ($depth) {
            $lowerDepth = $depth === INF ? INF : $depth - 1;
            foreach ($data as $key => $datum) {
                if ($lowerDepth >= 0 && is_iterable($datum)) {
                    $collection = $this::make($datum);

                    foreach ($collection->flatten($lowerDepth)->getIterator() as $item) {
                        yield $item;
                    }
                } else {
                    yield $datum;
                }
            }
        });
    }
public function flatten($depth = INF): CollectionInterface
    {
        return $this->wrap(function (Iterator $data) use ($depth) {
            $lowerDepth = $depth === INF ? INF : $depth - 1;
            foreach ($data as $key => $datum) {
                if ($lowerDepth >= 0 && is_iterable($datum)) {
                    $collection = $this::make($datum);

                    foreach ($collection->flatten($lowerDepth)->getIterator() as $item) {
                        yield $item;
                    }
                } else {
                    yield $datum;
                }
            }
        });
    }
public function flatten ( $ depth = INF ) : CollectionInterface { return $ this -> wrap ( function ( Iterator $ data ) use ( $ depth ) { $ lowerDepth = $ depth === INF ? INF : $ depth - 1 ; foreach ( $ data as $ key => $ datum ) { if ( $ lowerDepth >= 0 && is_iterable ( $ datum ) ) { $ collection = $ this :: make ( $ datum ) ; foreach ( $ collection -> flatten ( $ lowerDepth ) -> getIterator ( ) as $ item ) { yield $ item ; } } else { yield $ datum ; } } } ) ; }
Get a flattened array of the items in the collection.

@param  int $depth
@return CollectionInterface
Get a flattened array of the items in the collection .