Transducer. Takes a function fn which will be applied to each input value. If the function returns an ES6 Iterable, the result will be recursively flattened (via same user provided fn). If the function returns null/undefined, the original input value will be used as result.
remarks
Also see flatten. If src is given as well, yields iterator of results.
example
// custom predicate which converts objects into key/val tuples,// returns iterables as is and null for everything elseconst pred = (x) =>
isPlainObject(x)
? pairs(x)
: isNotStringAndIterable(x)
? x
: null;
[...flattenWith(pred, [{ a: 1, b: 2 }, [[{ c: 3 }]]])]
// [ 'a', 1, 'b', 2, 'c', 3 ]
Transducer. Takes a function
fn
which will be applied to each input value. If the function returns an ES6 Iterable, the result will be recursively flattened (via same user provided fn). If the function returns null/undefined, the original input value will be used as result.Also see flatten. If
src
is given as well, yields iterator of results.// custom predicate which converts objects into key/val tuples, // returns iterables as is and null for everything else const pred = (x) => isPlainObject(x) ? pairs(x) : isNotStringAndIterable(x) ? x : null; [...flattenWith(pred, [{ a: 1, b: 2 }, [[{ c: 3 }]]])] // [ 'a', 1, 'b', 2, 'c', 3 ]