reports/frontend/node_modules/es-toolkit/dist/compat/function/flow.mjs
jtricerolph 1c411e402e Add settings page for managing forecasting API key and URL via UI
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-07-20 14:37:36 +00:00

26 lines
971 B
JavaScript

import { flatten } from "../../array/flatten.mjs";
import { flow as flow$1 } from "../../function/flow.mjs";
//#region src/compat/function/flow.ts
/**
* Creates a new function that executes the given functions in sequence. The return value of the previous function is passed as an argument to the next function.
*
* The `this` context of the returned function is also passed to the functions provided as parameters.
*
* @param funcs The functions to invoke.
* @returns Returns the new composite function.
*
* @example
* 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);
* console.log(combined(1, 2)); // 18
*/
function flow(...funcs) {
const flattenFuncs = flatten(funcs, 1);
if (flattenFuncs.some((func) => typeof func !== "function")) throw new TypeError("Expected a function");
return flow$1(...flattenFuncs);
}
//#endregion
export { flow };