peek

Runs a function for each element without changing anything — the pipeline equivalent of a debugger breakpoint.

Iterable<A> peek<A>(void Function(A a) f, Iterable<A> iterable) FxAsyncIterable<A> peekAsync<A>(FutureOr<void> Function(A a) f, FxAsyncIterable<A> iterable) Fx<T> Fx.peek(void Function(T a) f) // chain FxAsync<T> FxAsync.peek(FutureOr<void> Function(T a) f)

Lecture

peek is mapEffect's stricter cousin: where mapEffect can still change the value (it's map under a different name), peek's callback returns void — it is only ever allowed to look. The element that went in comes back out completely untouched. Reach for it to drop a print, a metric, or a log line into the middle of a pipeline while debugging, without risking a typo that silently mutates the data.

It's just as lazy as everything else here: the callback fires exactly once per element that gets pulled through, in order, and not before.

peekAsync is built directly on top of mapAsync (it awaits f, then re-yields the original value), so it shares map's concurrency behavior exactly: .concurrent(n) genuinely runs n callbacks in parallel — unlike flatMap or scan, whose internal state machines have to stay sequential.

Demo 1 · Basics

Same values in, same values out — peek only ever observes:

Demo 2 · Async, with real concurrency

Try it yourself

Exercise: use peek to print 'checking price: $p' for each price without changing the values, then sum them with fold.

Related: mapEffect — like peek, but can transform · map — transform each element · pluck — pull one field out of each map · concurrent — parallel evaluation