{
"id": "fn-core-pipe",
"dataComponent": "core",
"heading": {
"title": "pipe",
"badges": [
"Core",
"PARTIAL"
]
},
"synopsis": "Combines multiple functions left-to-right, returning a single function. The output of one function flows to the next.",
"codeBlocks": [
"############################################\n# Example usage of pipe(...)\n############################################\n\n# 1) Suppose we have some functions:\n# string:upper => converts a single string to uppercase\n# string:length => returns the length of a single string\n# plus(10) => adds 10 to a number\n\nextend(\"string\")\nextend(\"array\")\n\n# 2) We create a pipeline using pipe:\n# The data flows from left to right.\n# So we first call string:upper on the input,\n# then string:length,\n# then plus(10),\n# then sput receives the final result.\n\nmyPipeline = pipe(\n string:upper,\n string:length,\n plus(10),\n sput\n)\n\n# 3) Now calling myPipeline(\"hello\") executes in left-to-right order:\n# - string:upper(\"hello\") => \"HELLO\"\n# - string:length(\"HELLO\") => 5\n# - plus(10)(5) => 15\n# - sput(15) => prints 15\n\nmyPipeline(\"hello\")\n# => prints 15\n"
],
"notes": [
"pipe(...) works similarly to compose, but the functions are executed from left to right: pipe(f, g, h)(x) => h(g(f(x))).",
"If you prefer right-to-left ordering, see compose(...).",
"You can partially apply pipe by providing fewer function arguments. Missing spots can use underscore placeholders. Once all functions are known, you get a single function to call with your data."
]
}