Skip to main content

Function: uniqueBy()

Returns an iterable containing the values of iterable in iteration order, except values for which fn returns the same value are deduplicated.

When values are deduplicated, the value earlier in iteration order wins.

Example

console.log(
pipe(
[`sloth`, `sleep`, `fast`, `slow`, `mean`],
uniqueBy(word => word.length),
reduce(toArray()),
),
)
//=> [ 'sloth', 'fast' ]

uniqueBy(fn)

uniqueBy<Value>(fn): (iterable) => Iterable<Value, any, any>

Returns an iterable containing the values of iterable in iteration order, except values for which fn returns the same value are deduplicated.

When values are deduplicated, the value earlier in iteration order wins.

Type Parameters

Value

Parameters

fn

Returns

Function

Parameters

iterable: Iterable<Value, any, any>

Returns

Iterable<Value, any, any>

Example

console.log(
pipe(
[`sloth`, `sleep`, `fast`, `slow`, `mean`],
uniqueBy(word => word.length),
reduce(toArray()),
),
)
//=> [ 'sloth', 'fast' ]

Defined in

filters.d.ts:328

uniqueBy(fn, iterable)

uniqueBy<Value>(fn, iterable): Iterable<Value, any, any>

Returns an iterable containing the values of iterable in iteration order, except values for which fn returns the same value are deduplicated.

When values are deduplicated, the value earlier in iteration order wins.

Type Parameters

Value

Parameters

fn

iterable: Iterable<Value, any, any>

Returns

Iterable<Value, any, any>

Example

console.log(
pipe(
[`sloth`, `sleep`, `fast`, `slow`, `mean`],
uniqueBy(word => word.length),
reduce(toArray()),
),
)
//=> [ 'sloth', 'fast' ]

Defined in

filters.d.ts:331