Skip to main content

Function: toWeakMap()

toWeakMap<Key, Value>(): RawKeyedReducer<Key, Value, WeakMap<Key, Value>>

Returns a KeyedReducer that collects key-value pairs to a WeakMap.

In the case of pairs with duplicate keys, the value of the last one wins.

Type Parameters

Key extends object

Value

Returns

RawKeyedReducer<Key, Value, WeakMap<Key, Value>>

Example

console.log(
pipe(
[`sloth`, `more sloth`, `even more sloth`],
map(string => [{ sloth: string }, string.length]),
reduce(toWeakMap()),
),
)
//=> WeakMap { <items unknown> }

Since

v0.0.1

Defined in

collections.d.ts:149