liveBook · Manning

Seq combinator

As explained in Functional Programming in JavaScript

A combinator that runs multiple functions in order on the same input value.

Functional code needs an alternative to procedural control flow such as loops and conditionals. The seq combinator runs several functions in order against the same input, coordinating their actions without adding variables or business logic. section 4.6

A small JavaScript implementation collects its function arguments, then calls each function with the supplied value. This makes seq useful when several operations—such as displaying information and logging it—should happen in order rather than form a value-transforming pipeline. section 4.6

Showing and logging a student

After finding and formatting a student, compose can pass the result to seq, which calls append('#student-info') and consoleLog in order. The functional version replaces the repeated procedural control flow with a reusable combinator. section 4.6

identity :: (a) -> a

The related listings show seq's implementation and its use inside a composed showStudent function. section 4.6

How Functional Programming in JavaScript covers it

How deep it goes
Defines seq and shows its JavaScript implementation and composed use, without descending into execution internals.
Examples
Uses a showStudent composition that appends student information and logs the same formatted result.
What it assumes
Assumes familiarity with JavaScript functions and introduces combinators as alternatives to imperative control flow.
What you can do after
Build it from scratch and apply it to coordinate ordered operations within a functional composition.
How it connects
Connects seq with higher-order functions, function combinators, compose, and pipe.

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.