Options
All
  • Public
  • Public/Protected
  • All
Menu

Module "xform/flatten-with"

Index

Type aliases

Functions

Type aliases

MaybeIterable

MaybeIterable<T>: Nullable<Iterable<T>>

Type parameters

  • T

Functions

flattenWith

  • 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 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 ]

    Type parameters

    • T

    Parameters

    Returns Transducer<T | Iterable<T>, T>

  • Type parameters

    • T

    Parameters

    Returns IterableIterator<T>

Generated using TypeDoc