PLDB
Languages Features Calendar CSV Lists Blog About Sponsor Add Language
GitHub icon

Function Composition

Function Composition

Function Composition is a feature.

In computer science, function composition is an act or mechanism to combine simple functions to build more complicated ones. Like the usual composition of functions in mathematics, the result of each function is passed as the argument of the next, and the result of the last one is the result of the whole.


Languages with Function Composition include JavaScript, C#, Haskell, APL, Coconut, Raku

Example from JavaScript:
function o(f, g) { return function(x) { return f(g(x)); } }
Example from C#:
// Call example: // var c = Compose(f, g); // // Func<int, bool> g = _ => ... // Func<bool, string> f = _ => ... Func<TIn, TOut> Compose<TIn, TMid, TOut>(Func<TMid, TOut> f, Func<TIn, TMid> g) => _ => f(g(_));
Example from Haskell:
foo = f . g
Example from APL:
foo←f∘g
Example from Coconut:
(f..g..h)(x, y, z)
Example from Raku:
my &foo = &f ∘ &g;
fixed-point-feature.html · function-composition-feature.html · generators-feature.html

View source

PLDB - Build the next great programming language · v2022 · Day 29 · Docs · Build · Acknowledgements · Traffic Today · Traffic Trends · Mirrors · GitHub · feedback@pldb.com