Compose functions from left to right

Build one function that passes a value through each function in order.

JavaScriptNode.js & browsers Version 1.0.0 · MIT · .md

compose-functions-from-left-to-right.js
function pipe(...fns) { return input => fns.reduce((value, fn) => fn(value), input); }

Usage

usage.js
const lowercase = text => text.toLowerCase();
const capitalize = text => text.charAt(0).toUpperCase() + text.slice(1);
const reverse = text => [...text].reverse().join('');
pipe(lowercase, capitalize, reverse)('HELLO'); // → 'olleH'
pipe()('unchanged'); // → 'unchanged'

Lines marked → were executed in Node.js 22 and in headless Chromium, and each result was compared with the value shown. Lines marked e.g. are illustrative.

Know the limits

  • Functions run in the order listed. With no functions, the input comes back unchanged.
  • Each step receives one value. For async steps, use a for…of loop with await.

The function above is the code the usage lines run. It does not validate its arguments; add checks where it receives untrusted input.

Source & maintenance

Based on Compose functions from left to right from the original 1loc collection by Nguyen Huu Phuoc. Copyright (c) 2020 phuoc-ng. MIT licensed.

Documented as a reference with executed usage lines. Original MDX retained as inert source evidence.

Maintained by Oveyon. Original source commit: 14b481cf60df. This edition’s file: contents/compose-functions-from-left-to-right.mdx in akamind/1loc, commit 0a77f131b22d. Read the license.

Usage lines executed in Node.js 22 and headless Chromium; no external services · reviewed October 28, 2026.

Keep exploring

Type two or more characters. Try “duplicate”, “webhook” or “retry”.