stream-stream-reduce.nix
Source: /nix/store/mls72plk3raskl1r5afh3cl9ik3rn969-source/nix/stream-reduce.nix
Module Description
Stream reduction operations - folding, collecting, and iterating
Combinators
fold
Reduces stream to single value with effectful accumulator.
Threads accumulator through stream, applying function to each element. The accumulator function can be effectful.
Type Signature
A -> (A -> V -> Fx<S, A>) -> Stream<S, V> -> Fx<S, A>
Parameters
initial: Initial accumulatorf: Accumulator functionstream: Source stream
Example
runFx (fold 0 (acc: x: pure (acc + x)) (fromList [1 2 3]))
# => 6
See Also
toList- Collect to listforEach- Execute for side effects
forEach
Executes an effect for each stream element.
Runs side effects while consuming stream. Returns unit. The effect can access and modify context.
Type Signature
(V -> Fx<S, {}>) -> Stream<S, V> -> Fx<S, {}>
Parameters
f: Effect to executestream: Source stream
Example
# Print each element (conceptually)
runFx (forEach (x: state.modify (s: s + x)) stream)
See Also
fold- Reduce with accumulatormap- Transform without consuming
toList
Collects all stream elements to a list.
Forces entire stream evaluation and gathers results. Be careful with infinite streams!
Type Signature
Stream<S, V> -> Fx<S, [V]>
Parameters
stream: Source stream
Example
runFx (toList (fromList [1 2 3])) # => [1 2 3]
See Also
fromList- Convert from listfold- Custom reduction
Generated from /nix/store/mls72plk3raskl1r5afh3cl9ik3rn969-source/nix/stream-reduce.nix