liveBook · Manning

Run

As explained in Functional Programming in JavaScript

A function that sequentially invokes a chain of functions, passing each result to the next.

run builds a larger function by connecting smaller functions in sequence. The result from one function becomes the input to the next, making behavior easier to reuse and extend. section 1.2

Compose a message printer

var printMessage = run(addToDom('msg'), h1, echo); printMessage('Hello World');. Each function contributes one step: create the target operation, format the heading, and supply the message. section 1.2

Listing 1.1. Functional printMessage
var printMessage = run(addToDom('msg'), h1, echo);

printMessage('Hello World');

Inspect the complete composed printMessage definition and its single-message invocation. section 1.2

The same pattern can extend a workflow without rewriting its pieces: run(console.log, repeat(2), h2, echo) adds logging, repetition, formatting, and output as separate functions. section 1.2

How Functional Programming in JavaScript covers it

How deep it goes
Defines sequential function composition through examples but does not detail run’s implementation.
Examples
Uses message rendering, console logging, repetition, formatting, database lookup, CSV conversion, and DOM updates.
What it assumes
Assumes basic JavaScript functions and parameters while teaching function-valued parameters through concrete examples.
What you can do after
Build reusable JavaScript workflows by arranging existing functions into a sequential chain.
How it connects
Connects function composition with reuse, modularity, side effects, and functional programming.

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.