Use Map.fetch as the example for error handling
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user