Skip to main content

Function: toObject()

toObject<Key, Value>(): RawKeyedReducer<Key, Value, Record<Key, Value>>

Returns a KeyedReducer that collects key-value pairs to an object.

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

Type Parameters

Key extends PropertyKey

Value

Returns

RawKeyedReducer<Key, Value, Record<Key, Value>>

Example

import { map, pipe, reduce, toObject } from 'lfi'

console.log(
pipe(
[`sloth`, `lazy`, `sleep`],
map(word => [word, word.length]),
reduce(toObject()),
),
)
//=> {
//=> sloth: 5,
//=> lazy: 4,
//=> sleep: 5
//=> }
Playground

Since

v0.0.1

Defined in

collections.d.ts:113