liveBook · Manning

Alt combinator

As explained in Functional Programming in JavaScript

A combinator that chooses between two alternative computations, returning the first defined result or otherwise the second.

The alt combinator replaces an if/else fallback with a reusable function. It applies two functions to the same input and returns the first usable result; otherwise, it returns the second. section 4.6

Find or create a student

An imperative version checks whether findStudent returns a result, then either formats that student or creates one. A functional rewrite composes alt(findStudent, createNewStudent) with csv and append, leaving the branching inside a reusable combinator.

How Functional Programming in JavaScript covers it

How deep it goes
Defines two-function fallback over one value and stops short of deeper theoretical treatment.
Examples
Uses student lookup-or-creation before CSV formatting and DOM output, alongside an equivalent if/else implementation.
What it assumes
Builds from familiar if/else control flow toward higher-order functions and functional composition.
What you can do after
Apply it via JavaScript functions to collapse fallback branching into a reusable composed pipeline.
How it connects
Connects alternation with higher-order functions, composition, currying, and data lookup.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Programming in JavaScript. The section links point to the parts of the book it draws on.