{
"id": "fn-core-compose",
"dataComponent": "core",
"heading": {
"title": "compose",
"badges": [
"Core",
"PARTIAL"
]
},
"synopsis": "Combines multiple functions right-to-left, returning a single function. The output of one function is passed as the input to the next.",
"codeBlocks": [
"############################################\n# Example usage of compose(...)\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 composition using compose:\n# The data flows from right to left.\n# So we first call string:length on the input,\n# then add 10, then sput will receive that final result.\n\nmyComp = compose(\n sput,\n plus(10),\n string:length\n)\n\n# 3) Now we can call 'myComp' with a single argument.\n# Because of composition’s right-to-left flow:\n# - The argument goes to string:length\n# - The result of that goes to plus(10)\n# - Finally, that goes into sput.\n\nmyComp(\"hello\")\n# => 15 (because \"hello\" is length 5, plus 10 => 15)\n"
],
"notes": [
"compose(...) processes arguments from the rightmost function to the leftmost, similar to how nested function calls work: f(g(h(x))).",
"If you need left-to-right ordering, see pipe(...).",
"You can partially apply compose by providing fewer arguments, using underscore placeholders for the missing function slots. Once all slots are known, it yields a single function that you can invoke with your data."
]
}