Merge pull request #149 from dillonkearns/master

Anonymous functions using & for arbitary expressions
This commit is contained in:
Felipe Seré
2016-10-30 11:07:45 +00:00
committed by GitHub
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",