4.0.0 • Published 7 years ago

starry.group-by v4.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Member of the starry suite—modular functions for iterable objects.

npm node

Status

Applies to the whole suite.

Build Status Coverage Status

Usage

function groupBy<TItem = any, TKey = any, TValue = any>(
  iterable: Iterable<TItem>,
  keySelector: (item: TItem) => TKey = x => x as TItem & TKey,
  valueSelector: (item: TItem) => Tvalue = x => x as TItem & TValue
): Map<TKey, TValue[]>

Groups the elements of an iterable into a map.

Parameters:

  • iterable - Iterable<TItem>
  • keySelector - (item: TItem) => TKey: A function to extract the key for each element. Default: x => x
  • valueSelector - (item: TItem) => TValue: A function to map each element into the output grouping. Default: x => x

Returns: Map<TKey, TValue>