Working with map, filter, fold, and apply

Build deterministic pipelines from left-to-right collection traversal and keep callback arity and result contexts explicit.

At a glance

LISPEX
(reduce + 0 (map (lambda (x) (* x x)) (filter odd? (list 1 2 3 4))))

Result

OUTPUT
10

Working method

  • Use map for one result per element, filter for truth-valued selection, and folds for one accumulated result.
  • Callbacks execute as guest procedures, so errors, escapes, warnings, and value-context rules remain active.
  • Use apply when a final proper list should become positional arguments; it preserves tail application.

Boundaries

  • A callback that yields zero or multiple values in a single-value traversal position raises E320.