Use Map.fetch as the example for error handling

This commit is contained in:
Uku Taht
2016-03-08 13:01:12 +02:00
parent fee07e99a6
commit 0fbbd30b5c

View File

@@ -59,11 +59,11 @@ defmodule PatternMatching do
end
koan "errors are shaped differently than sucessful results" do
result = case Integer.parse("obviously not a number") do
{parsed, _} -> parsed
:error -> 0
result = case Map.fetch(%{}, :obviously_not_a_key) do
{:ok, val} -> val
:error -> "not present"
end
assert result == 0
assert result == "not present"
end
end