Skip to content

groupBy

groupBy<A>(keyFn): (items) => Readonly<Record<string, readonly A[]>>

Defined in: Utils/Rec.ts:156

Groups elements of an array into a record keyed by the result of keyFn. Each key maps to the array of elements that produced it, in insertion order.

Unlike Dict.groupBy, keys are always strings. Use Dict.groupBy when you need non-string keys or want to avoid the plain-object prototype chain.

A

(a) => string

(items): Readonly<Record<string, readonly A[]>>

readonly A[]

Readonly<Record<string, readonly A[]>>

pipe(
  ["apple", "avocado", "banana", "blueberry"],
  Rec.groupBy(s => s[0]),
); // { a: ["apple", "avocado"], b: ["banana", "blueberry"] }