Composition

Published: 1/18/2020
Last edited: 1/26/2020

An operation which takes two or more functions and returns a unary function.

Function composition facilitates code re-use.

const f = x =>  x
const g = x => y
const h = x => f(g(x))
// or, es6 style:
import { pipe } from 'ramda'
const h = pipe(f, g)
// if you need to roll your own
const pipe = (...fns) => (
  x => fns.reduce(
    (prev, fn) => fn(prev),
    x
  )
)
Published: 1/18/2020
Last edited: 1/26/2020
See this page on Github
Built with 💛 by Open Sorcerers
Created with Gatsby using the 😎 foresight starter