You may have seen in math classes that it can be useful to compose multiple functions together. In computer science, this basically means that we want to take the output of one function and pass it into the input of another. Press the dog-eared page button on the top left and click libraries. Click on Iteration, Composition at the very top and import it. Now you should have this block:
compose, which does just that. It takes in two functions, f
and g
and returns the
function f(g)
. For example, this
will return a function that is equivalent to
For example
will return 18
(the result of the calculation 2 * (6 + 3)
). Notice that when we call
ed
the result of compose
, we didn't use
a gray border. To do this, you can right click compose and click "unringify". This is because compose
already returns a function.
Now try writing
which returns the result of composing the functions in the input list, from left to right. So, when called like this
a function equivalent to this
will be returned.