Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add koan "You can use pattern matching to define [...]" #224

Merged
merged 3 commits into from
Jul 12, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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

Expand Down