Skip to main content

Module: util/itertools

Functions

groupBy

groupBy<T, U>(list, func): Map<U, T[]>

Returns a map where the elements are grouped based on the value of func for the given elements.

Type parameters

Name
T
U

Parameters

NameTypeDescription
listT[]LIst of elements to group
func(element: T) => UFunction to map elements to group key

Returns

Map<U, T[]>

Map from group keys to list of elements mapped to given key

Defined in

util/itertools.ts:8


partition

partition<T, U>(list, predicate): [T[], U[]]

Partitions a list into two lists, one containing all elements for which the predicate returned true, the other containing all elements for which the predicate returned false

Type parameters

Name
T
U

Parameters

NameTypeDescription
list(T | U)[]The list to partition
predicate(elem: T | U) => elem is TThe predicate to use to partition the list

Returns

[T[], U[]]

A tuple of two lists, the first containing all elements for which the predicate returned true, the second containing all elements for which the predicate returned false

Defined in

util/itertools.ts:38