import type { DeepArrayValue , Fn , Nullable } from "@thi.ng/api" ; import { isIterable } from "@thi.ng/checks/is-iterable" ; import { isString } from "@thi.ng/checks/is-string" ; import type { Reducer , Transducer } from "./api.js" ; import { compR } from "./compr.js" ; import { iterator } from "./iterator.js" ; import { isReduced } from "./reduced.js" ; type MaybeIterable < T > = Nullable < Iterable < T > > ; remarks Also see  flatten . If `src` is given as well, yields iterator
 * of results.
 *
 *  example param fn param src export function flattenWith < A , B = DeepArrayValue < A > > ( fn ) ; export function flattenWith < A , B = DeepArrayValue < A > > ( fn , src ) ; export function flattenWith < A > ( fn , src ? ) { return isIterable ( src ) ? iterator ( flattenWith ( fn ) , isString ( src ) ? < any > [ src ] : src ) : ( rfn ) => { const reduce = rfn [ 2 ] ; const flatten = ( acc , x ) => { const xx = fn ( x ) ; if ( xx ) { for ( let y of xx ) { acc = flatten ( acc , y ) ; if ( isReduced ( acc ) ) { break ; } } return acc ; } return reduce ( acc , x ) ; } ; return compR ( rfn , flatten ) ; } ; }