Add koans to practice building anonymous functions using & for arbitrary expressions

This commit is contained in:
Dillon Kearns
2016-10-29 23:05:08 -04:00
parent cdd83644c0
commit 490fa050e5
2 changed files with 12 additions and 0 deletions

View File

@@ -67,6 +67,16 @@ defmodule Functions do
assert multiply.(2,3) == ___
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 square(number), do: number * number

View File

@@ -13,6 +13,8 @@ defmodule FunctionsTests do
{:multiple, ["The number was zero", "The number was 5"]},
6,
6,
"Hello, Foo!",
["foo", "foo", "foo"],
100,
1000,
"Full Name",