Creates a sink collecting items into a map using item values.
The type of items in the stream
The type of map keys
The function to extract the key from each item
A sink that collects items into a map with keys from the key selector and items as values
await items([{ id: 1, name: "Alice" }, { id: 2, name: "Bob" }])(toMap(x => x.id));// Map(2) { 1 => { id: 1, name: "Alice" }, 2 => { id: 2, name: "Bob" } } Copy
await items([{ id: 1, name: "Alice" }, { id: 2, name: "Bob" }])(toMap(x => x.id));// Map(2) { 1 => { id: 1, name: "Alice" }, 2 => { id: 2, name: "Bob" } }
Creates a sink collecting items into a map using custom keys and values.
The type of map values
The function to transform each item into a map value
A sink that collects items into a map with keys and values from the selectors
await items([{ id: 1, name: "Alice" }, { id: 2, name: "Bob" }])(toMap(x => x.id, x => x.name));// Map(2) { 1 => "Alice", 2 => "Bob" } Copy
await items([{ id: 1, name: "Alice" }, { id: 2, name: "Bob" }])(toMap(x => x.id, x => x.name));// Map(2) { 1 => "Alice", 2 => "Bob" }
Creates a sink collecting items into a map using item values.