intermediate

Pure functions, currying, and composition

Purity, side effects, partial application, currying, and composing small transformations.

Pure functions return the same output for the same input and avoid observable side effects. They are easy to test but should not be pursued at the cost of readability.

Currying transforms `f(a, b)` into `f(a)(b)` — useful for reusable configuration. Composition chains small transforms: `const normalize = pipe(trim, toLowerCase)`.

A function that reads `Date.now()`, mutates input, or touches globals is not pure.

On interviews, explain the concept with a concrete example and name the runtime behavior interviewers probe.

Common pitfalls include mixing similar APIs and forgetting edge cases during live coding.

Checklist:

  • Check side effects before calling pure.
  • Keep data flow named and readable.
  • Avoid clever point-free pipelines.