reduceLazy

Curries fold's seed and combiner into a reusable reducer function.

Acc Function(Iterable<A>) reduceLazy<A, Acc>(Acc Function(Acc acc, A a) f, Acc seed)

Lecture

reduceLazy doesn't reduce anything by itself — it builds a reducer. Give it a combining function and a seed, and you get back a plain function of type Iterable<A> Function that you can call as many times as you like, against as many different iterables as you like, without repeating the seed and combiner every time.

Under the hood it's just a thin wrapper around fold: reduceLazy(f, seed) returns (iterable) => fold(seed, f, iterable). Notice the argument order flips relative to fold — here it's (f, seed), matching FxTS's curried style, where the iterable is deliberately left off until later.

This is a plain (uncurried-beyond-this) Dart function, so there's no Fx chain method or *Async counterpart for it — but the function it returns happens to accept anything that implements Iterable<A>, which includes Fx<A>. That means you can drop it straight into .to(...) on a chain.

Demo 1 · A reusable summer

Demo 2 · Reused across different lists

The whole point is defining the "how to combine" once and reusing it everywhere:

Try it yourself

Exercise: build a reusable reducer with reduceLazy that finds the max value.

Related: fold — the seeded reducer this wraps · reduce — the unseeded terminal · pipe — compose functions like this into a pipeline · memoize — another way to build a reusable function