liveBook · Manning

Higher-kinded composition

As explained in The Joy of JavaScript

A composition approach in which objects compose through higher-level interfaces or abstractions analogous to function composition.

Higher-kinded composition makes objects compose through higher-level interfaces, much as functions compose by passing outputs into inputs. Algebraic data types (ADTs) provide this object-level composability. section 5.0

Function composition works cleanly when inputs are valid and operations cannot fail. Validation, null values, and exceptions complicate that model, so ADTs represent one concept—such as validation or error handling—behind a concise composable interface. section 5.0

The pattern shifts branching and failure handling into composable operations:

  • Model a single concern with an ADT rather than a broad class. section 5.0
  • Expose an interface that lets similar abstractions chain together. section 5.0

Composable validation

A validation pipeline can chain length, tampering, difficulty, linkage, and timestamp checks with successive flatMap calls instead of embedding guards before every function.

How The Joy of JavaScript covers it

How deep it goes
Defines ADTs and demonstrates chained validation, but does not descend into their internal implementation.
Examples
Uses repeated validation guards, try/catch wrappers, and a flatMap chain for blockchain-style checks.
What it assumes
Assumes familiarity with function composition and higher-order functions while introducing ADTs for failure-aware composition.
What you can do after
Build it from scratch by modeling concerns as ADTs and chaining their operations into composable validation pipelines.
How it connects
Connects higher-kinded composition to function composition, higher-order functions, algebraic data types, validation, and error handling.

Related concepts

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