# Compose functions from left to right

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

Canonical: https://1loc.dev/function/compose-functions-from-left-to-right/
Version: 1.0.0
Runtime: JavaScript · Node.js 22 / modern browsers
Verification: Usage lines executed in Node.js 22 and headless Chromium; no external services
Updated: 2026-10-28

## Implementation

```javascript
function pipe(...fns) { return input => fns.reduce((value, fn) => fn(value), input); }
```

## Usage

```javascript
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.

## 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 does not validate its arguments. Add checks where it receives untrusted input.

## Source and license

Original: https://github.com/phuocng/1loc/blob/14b481cf60dff1620ab1bb99a43b1f68068cdd9b/contents/compose-functions-from-left-to-right.mdx
Source file (this edition): https://github.com/akamind/1loc/blob/0a77f131b22d2ba3b7ec1728846f900c22821678/contents/compose-functions-from-left-to-right.mdx
Author: Nguyen Huu Phuoc and original contributors
Contributors: See original repository history
Source commit: 14b481cf60dff1620ab1bb99a43b1f68068cdd9b
Copyright (c) 2020 phuoc-ng
License: MIT — https://1loc.dev/licenses/
Maintainer: Oveyon
Modifications: Documented as a reference with executed usage lines. Original MDX retained as inert source evidence.
