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 string
| number
| symbol
• Value
Returns
RawKeyedReducer
<Key
, Value
, Record
<Key
, Value
>>
Example
console.log(
pipe(
[`sloth`, `more sloth`, `even more sloth`],
map(string => [string, string.length]),
reduce(toObject()),
),
)
//=> { sloth: 5, 'more sloth': 10, 'even more sloth': 15 }