Created
September 28, 2017 13:05
-
-
Save tmock12/d248706f46a86311c8f2a63bf7838784 to your computer and use it in GitHub Desktop.
with-sad-path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
some_map = %{foo: "bar", ping: "pong", ding: "dong"} | |
with :error <- Map.fetch(some_map, :nope), | |
:error <- Map.fetch(some_map, :nada), | |
:error <- Map.fetch(some_map, :nilch) do | |
"default value" | |
else | |
{:ok, value} -> value | |
end | |
#> "default value" | |
with :error <- Map.fetch(some_map, :nope), | |
:error <- Map.fetch(some_map, :nada), | |
:error <- Map.fetch(some_map, :ping) do | |
"default value" | |
else | |
{:ok, value} -> value | |
end | |
#> "pong" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment