Skip to content

partition

Call Signature

partition<U, T>(xs, by): Partition<U, T>

Partitions a Iterable into disjoint arrays of results. The first array of the result contains the items that match the predicate. The second array of the result contains the items that didn’t match the predicate.

Example

partition([1, 'a'], isString)
// => [['a'], [1]]

Alternatives

Type Parameters

U

The element type of the input.

T

The element type for the first partition.

Parameters

xs

Iterable<U>

The values to partition.

by

(item, index) => item is T

Returns

Partition<U, T>

The partitions.

Call Signature

partition<T>(xs, by): [T[], T[]]

Partitions a Iterable into disjoint arrays of results. The first array of the result contains the items that match the predicate. The second array of the result contains the items that didn’t match the predicate.

Example

partition([1, 'a'], isString)
// => [['a'], [1]]

Alternatives

Type Parameters

T

The element type for the first partition.

Parameters

xs

Iterable<T>

The values to partition.

by

(item, index) => boolean

Returns

[T[], T[]]

The partitions.