Merge pull request #224 from s-oram/add_anonymous_fn_koan
Add koan "You can use pattern matching to define [...]"
This commit is contained in:
@@ -78,6 +78,16 @@ defmodule Functions do
|
|||||||
assert three_times.("foo") == ___
|
assert three_times.("foo") == ___
|
||||||
end
|
end
|
||||||
|
|
||||||
|
koan "You can use pattern matching to define multiple cases for anonymous functions" do
|
||||||
|
inspirational_quote = fn
|
||||||
|
{:ok, result} -> "Success is #{result}"
|
||||||
|
{:error, reason} -> "You just lost #{reason}"
|
||||||
|
end
|
||||||
|
|
||||||
|
assert inspirational_quote.({:ok, "no accident"}) == ___
|
||||||
|
assert inspirational_quote.({:error, "the game"}) == ___
|
||||||
|
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
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ defmodule FunctionsTests do
|
|||||||
6,
|
6,
|
||||||
"Hi, Foo!",
|
"Hi, Foo!",
|
||||||
["foo", "foo", "foo"],
|
["foo", "foo", "foo"],
|
||||||
|
{:multiple, ["Success is no accident", "You just lost the game"]},
|
||||||
100,
|
100,
|
||||||
1000,
|
1000,
|
||||||
"Full Name",
|
"Full Name",
|
||||||
|
|||||||
Reference in New Issue
Block a user