import { Pipe } from "../pipe.js"; import { Yields } from "../util/index.js"; export function flat(depth?: number): Pipe { depth = (typeof depth === 'number' && depth >= 1) ? depth : 1; return () => { return (result: IteratorResult): IteratorResult | Array> => { if (result?.done || typeof result.value[Symbol.iterator] !== 'function') { return result; } return Yields(Array.from(result.value).flat(depth)); }; } }