Prelude API
    Preparing search index...

    Function map

    • Creates a function that transforms each value in an iterable using a mapping function. Similar to Array.prototype.map, but for any iterable.

      Type Parameters

      • T

        The type of elements in the input iterable

      • R

        The type of elements in the output iterable

      Parameters

      • mapping: (value: T, index: number) => R

        Function that transforms each value; receives value and index

      Returns (values: Iterable<T>) => Generator<R, void, unknown>

      A function that takes an iterable and yields mapped values

      Values transformed by the mapping function

      // Double each number
      const double = G.map(x => x * 2);
      const result = Array.from(double([1, 2, 3])); // [2, 4, 6]

      // Use with index
      const withIndex = G.map((x, i) => `${i}: ${x}`);
      const result2 = Array.from(withIndex(['a', 'b', 'c'])); // ['0: a', '1: b', '2: c']

      flatMap - For mapping one input to multiple outputs