For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/function/flow.md.

flow es-toolkit

Creates a new function that executes multiple functions in sequence.

const combinedFunc = flow(func1, func2, func3);

Usage

flow(...funcs)

Use flow when you want to chain functions together to create a pipeline. The result of the previous function becomes the input of the next function. This is useful for transforming data through multiple steps.

import { flow } from 'es-toolkit/function';

const add = (x: number, y: number) => x + y;
const square = (n: number) => n * n;
const double = (n: number) => n * 2;

const combined = flow(add, square, double);

// First add(1, 2) = 3
// Then square(3) = 9
// Finally double(9) = 18
combined(1, 2);
// Returns: 18

This is especially useful for creating data transformation pipelines.

const processData = flow(
  (text: string) => text.trim(),
  (text: string) => text.toLowerCase(),
  (text: string) => text.split(' '),
  (words: string[]) => words.filter(word => word.length > 3)
);

processData('  Hello World JavaScript  ');
// Returns: ['hello', 'world', 'javascript']

Parameters

funcsArray<(...args: any[]) => any>required

The functions to execute in sequence.

Returns

A new function that executes the given functions in sequence. The first function can accept multiple arguments, and the remaining functions receive the result of the previous function.

(...args: any[]) => any
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.