Skip to content

Commit cca671e

Browse files
authored
Merge pull request elixirkoans#224 from s-oram/add_anonymous_fn_koan
Add koan "You can use pattern matching to define [...]"
2 parents bde621c + 9fabb2b commit cca671e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/koans/13_functions.ex

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ defmodule Functions do
7878
assert three_times.("foo") == ___
7979
end
8080

81+
koan "You can use pattern matching to define multiple cases for anonymous functions" do
82+
inspirational_quote = fn
83+
{:ok, result} -> "Success is #{result}"
84+
{:error, reason} -> "You just lost #{reason}"
85+
end
86+
87+
assert inspirational_quote.({:ok, "no accident"}) == ___
88+
assert inspirational_quote.({:error, "the game"}) == ___
89+
end
90+
8191
def times_five_and_then(number, fun), do: fun.(number * 5)
8292
def square(number), do: number * number
8393

test/koans/functions_koans_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ defmodule FunctionsTests do
1515
6,
1616
"Hi, Foo!",
1717
["foo", "foo", "foo"],
18+
{:multiple, ["Success is no accident", "You just lost the game"]},
1819
100,
1920
1000,
2021
"Full Name",

0 commit comments

Comments
 (0)