diff --git a/lib/koans/13_functions.ex b/lib/koans/13_functions.ex index c20a4785..18a0c66b 100644 --- a/lib/koans/13_functions.ex +++ b/lib/koans/13_functions.ex @@ -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 + format_result = fn + {:ok, result} -> "Success is #{result}" + {:error, reason} -> "You just lost #{reason}" + end + + assert format_result.({:ok, "no accident"}) == ___ + assert format_result.({:error, "the game"}) == ___ + end + def times_five_and_then(number, fun), do: fun.(number * 5) def square(number), do: number * number