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 end
koan "errors are shaped differently than sucessful results" do koan "errors are shaped differently than sucessful results" do
result = case Integer.parse("obviously not a number") do result = case Map.fetch(%{}, :obviously_not_a_key) do
{parsed, _} -> parsed {:ok, val} -> val
:error -> 0 :error -> "not present"
end end
assert result == 0 assert result == "not present"
end end
end end