Function groupBy

  • Groups consecutive keys in the input iterator by some key identifier function or property. Functionally equivalent to the itertools.groupby function in Python. Generally the input iterator needs to be sorted by the same key. Each iteration will return the next group of values with the same key, until the key changes. So unless the input iterator is sorted beforehand, you may have broken up groups with the same keys.

    Type Parameters

    Parameters

    • arg: T

      The input iterator or iterable.

    • Optionalkey: Iteratee<string, U>

      The key identifier function or property name. If left undefined, and the value is a primitive, the value itself is used as a key. Iterators for object like values must use a key identifier.

    Returns IterableIterator<[U, string[]]>

    groupby('AAAABBBCCDAABBB') // =>
    // ['A', ['A', 'A', 'A', 'A']],
    // ['B', ['B', 'B', 'B']],
    // ['C', ['C', 'C']],
    // ['D', ['D']],
    // ['A', ['A', 'A']],
    // ['B', ['B', 'B', 'B']]
  • Type Parameters

    Parameters

    Returns IterableIterator<[U, number[]]>

  • Type Parameters

    Parameters

    Returns IterableIterator<[U, boolean[]]>

  • Type Parameters

    Parameters

    • arg: T
    • Optionalkey: K

    Returns IterableIterator<[KeyIdentifiersValue<IterSource<T>, K>, IterSource<T>[]]>