Add koans to practice building anonymous functions using & for arbitrary expressions
This commit is contained in:
@@ -67,6 +67,16 @@ defmodule Functions do
|
|||||||
assert multiply.(2,3) == ___
|
assert multiply.(2,3) == ___
|
||||||
end
|
end
|
||||||
|
|
||||||
|
koan "Prefix a string with & to build a simple anonymous greet function" do
|
||||||
|
greet = &"Hello, #{&1}!"
|
||||||
|
assert greet("Foo") == ___
|
||||||
|
end
|
||||||
|
|
||||||
|
koan "You can build anonymous functions out of any elixir expression by prefixing it with &" do
|
||||||
|
three_times = &[&1, &1, &1]
|
||||||
|
assert three_times.("foo") == ___
|
||||||
|
end
|
||||||
|
|
||||||
def times_five_and_then(number, fun), do: fun.(number*5)
|
def times_five_and_then(number, fun), do: fun.(number*5)
|
||||||
def square(number), do: number * number
|
def square(number), do: number * number
|
||||||
|
|
||||||
|
@@ -13,6 +13,8 @@ defmodule FunctionsTests do
|
|||||||
{:multiple, ["The number was zero", "The number was 5"]},
|
{:multiple, ["The number was zero", "The number was 5"]},
|
||||||
6,
|
6,
|
||||||
6,
|
6,
|
||||||
|
"Hello, Foo!",
|
||||||
|
["foo", "foo", "foo"],
|
||||||
100,
|
100,
|
||||||
1000,
|
1000,
|
||||||
"Full Name",
|
"Full Name",
|
||||||
|
Reference in New Issue
Block a user