Functional Composition
f + g
Performs functional composition on the two operands. Returns a function which passes its arguments to
g
and then too f
.The following are equivilent:
(f + g)(a,b) == f(g(a,b))
An example to change a zero-indexed function to a one-indexed function utilizing composition is:
let fibonacci = n f -> n < 2 ? 1 : f(n - 1) + f(n - 2);
let increment = (+) & 1;
( fibonacci + increment )( 5 ) == 13
Last modified 2yr ago