Functional Composition

Syntax

1
f + g
Copied!

Explanation

Performs functional composition on the two operands. Returns a function which passes its arguments to g and then too f.
The following are equivilent:
1
(f + g)(a,b) == f(g(a,b))
Copied!

Examples

An example to change a zero-indexed function to a one-indexed function utilizing composition is:
1
let fibonacci = n f -> n < 2 ? 1 : f(n - 1) + f(n - 2);
2
let increment = (+) & 1;
3
4
( fibonacci + increment )( 5 ) == 13
Copied!
Last modified 1yr ago
Copy link