Function groupMapReducingBy

  • Groups the elements of an array into a map, with the key being based on a key mapper, and the value being the values for the same key mapper result being reduced.

    Since

    11.0.0

    See

    • groupMapBy
    • countMapBy

    Returns

    Grouped and reduced map.

    Example

    groupMapReducingBy(
    ["foo", "bar", "fizz", "buzz"],
    val => val.charAt(0),
    () => {
    return {
    count: 0,
    matches: []
    };
    },
    (current, val) => {
    current.count++;
    current.matches.push(val);
    return current;
    }
    )
    // => Map{"f": {count: 2, matches: ["foo", "fizz"]}, "b": {count: 2, matches: ["bar", "buzz"]}}

    Type Parameters

    • TValue

    • UKey

    • VReduced

    Parameters

    • array: readonly TValue[]

      Array to group.

    • keyMapper: ArrayIterator<TValue, UKey>

      Function returning the key for the value.

    • initializer: ArrayIterator<TValue, VReduced>

      Function initializing a new reduction result object.

    • reducer: ((current: VReduced, value: TValue, index: number, collection: readonly TValue[]) => VReduced)

      Consumer creating a new reduction result object based on the previous result and the new data.

        • (current: VReduced, value: TValue, index: number, collection: readonly TValue[]): VReduced
        • Parameters

          • current: VReduced
          • value: TValue
          • index: number
          • collection: readonly TValue[]

          Returns VReduced

    Returns Map<UKey, VReduced>

Generated using TypeDoc