Add function capturing

This commit is contained in:
Felipe Sere
2016-01-13 22:20:21 +00:00
parent 8e91473ab8
commit 15108425ea

View File

@@ -86,4 +86,10 @@ defmodule Functions do
koan "You can also show that certain arguments are ignored in the body by adding an underscore" do koan "You can also show that certain arguments are ignored in the body by adding an underscore" do
assert two_arguments(:hi_there, "the other one") == "the other one" assert two_arguments(:hi_there, "the other one") == "the other one"
end end
def multiply_then_call(number, fun), do: fun.(number*5)
def square(number), do: number * number
koan "You can 'capture' functions if you want to pass them around as values" do
assert multiply_then_call(2, &square/1) == 100
end
end end