Skip to content

Commit

Permalink
Merge pull request #224 from s-oram/add_anonymous_fn_koan
Browse files Browse the repository at this point in the history
Add koan "You can use pattern matching to define [...]"
  • Loading branch information
felipesere committed Jul 12, 2018
2 parents bde621c + 9fabb2b commit cca671e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/koans/13_functions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ defmodule Functions do
assert three_times.("foo") == ___
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 square(number), do: number * number

Expand Down
1 change: 1 addition & 0 deletions test/koans/functions_koans_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ defmodule FunctionsTests do
6,
"Hi, Foo!",
["foo", "foo", "foo"],
{:multiple, ["Success is no accident", "You just lost the game"]},
100,
1000,
"Full Name",
Expand Down

0 comments on commit cca671e

Please sign in to comment.