Function Composition

suggest change

Composing multiple functions into one is a functional programming common practice;

composition makes a pipeline through which our data will transit and get modified simply working on the function-composition (just like snapping pieces of a track together)…

you start out with some single responsibility functions:

const capitalize = x => x.replace(/^\w/, m => m.toUpperCase());
const sign = x => x + ',\nmade with love';

and easily create a transformation track:

const formatText = compose(capitalize, sign);

formatText('this is an example')
// This is an example,
// made with love

N.B. Composition is achieved through a utility function usually called compose as in our example.

Implementation of compose are present in many JavaScript utility libraries (lodash, rambda, etc.) but you can also start out with a simple implementation such as:

const compose = (...funs) =>
  x =>
  funs.reduce((ac, f) => f(ac), x);

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Functions:
* Syntax
* Function Composition

Table Of Contents
11 Arrays
12 Objects
14 Classes
16 Map
17 Set
24 Loops
25 Functions
27 Date
29 Scope
30 AJAX
35 Cookies
41 JSON
44 Fetch
45 Modules
46 Screen
64 Console
68 Symbols
73 Modals
76 Events
86 Proxy
89 WeakMap
90 WeakSet
102 Tilde