Prelude API
    Preparing search index...

    Function group

    • Creates a function that groups elements from an iterable based on keys generated by a mapping function.

      Type Parameters

      • T

        The type of elements in the input iterable

      • K

        The type of keys used for grouping

      Parameters

      • keyOfValue: (value: T) => K

        A function that extracts a key from each value

      Returns (values: Iterable<T>) => MapIterator<[K, T[]]>

      A function that takes an iterable and yields entries of [key, group of values]

      Entries where each entry is a tuple of [key, values] with values being all elements that map to that key

      // Group numbers by even/odd
      const byParity = G.group(x => x % 2 === 0 ? 'even' : 'odd');
      const result = Array.from(byParity([1, 2, 3, 4, 5]));
      // [['odd', [1, 3, 5]], ['even', [2, 4]]]
      • groupMap - For getting a Map instead of entries iterator
      • groupObject - For getting an object instead of entries iterator