fxTap
Calls a function with a value for its side effect, then returns the value unchanged.
Lecture
fxTap is data-first: fxTap(f, value) runs
f(value) — usually a print, a log call, or some
other side effect — and then hands value straight back
unchanged. It exists so you can peek at a value without breaking the
expression it's part of: wrap any single value in fxTap
and the surrounding code doesn't need to change at all.
fxTap operates on one value at a time. Its cousin
peek is the pipeline version — it
runs a side effect for every element of an Iterable as it's
pulled through. For a curried, reusable "logger" you close over
f yourself: (v) => fxTap(f, v), as shown below.
Demo 1 · Basics
Demo 2 · Logging inside a pipe
Closing over fxTap gives a reusable "curried" logger you can
drop into a pipe chain to inspect intermediate values without
altering the flow of data:
Try it yourself
Exercise: use fxTap to print each value as it flows through
the map callback, before it gets multiplied by 10.
peek — the pipeline version of tap ·
fxPipe1 / pipe — compose a value through functions ·
fxIdentity — pass through with no side effect at all ·
fxApply — invoke a function with a dynamic argument list