Function flatMap

  • Maps the input iterator to a new value R and flattens any resulting iterables or iterators by a depth of 1. Behaves the same as Array.prototype.flatMap.

    Strings returned from iteratee are not flattened into characters. Return an array (e.g. [...str]) when you want character-level results.

    Type Parameters

    Parameters

    Returns IterableIterator<R>

    [...flatMap(['123'], str => str)]; // ['123']
    [...flatMap(['123'], str => [...str])]; // ['1', '2', '3']
  • Maps the input iterator to a new value R and flattens any resulting iterables or iterators by a depth of 1. Behaves the same as Array.prototype.flatMap.

    Strings returned from iteratee are not flattened into characters. Return an array (e.g. [...str]) when you want character-level results.

    Type Parameters

    Parameters

    Returns (arg: T) => IterableIterator<R>

    [...flatMap(['123'], str => str)]; // ['123']
    [...flatMap(['123'], str => [...str])]; // ['1', '2', '3']