Creates a sink reducing the stream to a single value without an initial value.
The type of items in the stream
The function to combine the accumulator with each item
A sink that reduces the stream to a single value, the first item for singleton streams, or undefined for empty streams
undefined
await items([1, 2, 3, 4, 5])(reduce((acc, x) => acc + x)); // 15await items([42])(reduce((acc, x) => acc + x)); // 42await items([])(reduce((acc, x) => acc + x)); // undefined Copy
await items([1, 2, 3, 4, 5])(reduce((acc, x) => acc + x)); // 15await items([42])(reduce((acc, x) => acc + x)); // 42await items([])(reduce((acc, x) => acc + x)); // undefined
Creates a sink reducing the stream to a single value with an initial value.
The type of the accumulated result
The initial value for the accumulator
A sink that reduces the stream to a single value
await items([1, 2, 3, 4, 5])(reduce((acc, x) => acc + x, 0)); // 15await items([1, 2, 3, 4, 5])(reduce((acc, x) => acc + x, 10)); // 25await items([])(reduce((acc, x) => acc + x, 0)); // 0 Copy
await items([1, 2, 3, 4, 5])(reduce((acc, x) => acc + x, 0)); // 15await items([1, 2, 3, 4, 5])(reduce((acc, x) => acc + x, 10)); // 25await items([])(reduce((acc, x) => acc + x, 0)); // 0
Creates a sink reducing the stream to a single value without an initial value.