juxt
Applies every function in a list to the same value and collects the results.
Lecture
Give juxt a list of functions that all accept the same
input, and it gives you back one function that runs the input through
every one of them and returns a List of the results, in
order. It's a compact way to compute several independent views of a
single value without repeating yourself.
FxTS's juxt is variadic and can accept functions with
different argument counts. Dart has no variadic generics, so FxDart's
version takes a single unary function T -> R per entry
— still enough to cover the common case of "run these N read-only
projections against this one value."
Demo 1 · Basics
The classic example from the dartdoc: computing the min and max of a list in one pass:
Demo 2 · Projecting several fields
Pulling multiple fields out of a record-like Map at once:
Try it yourself
Exercise: use juxt to compute the sum and
average of this list in a single pass.