Last active
September 3, 2016 17:29
-
-
Save expede/11fad9ee2e56afcd2129b2acaecd4c27 to your computer and use it in GitHub Desktop.
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
# ===================== | |
# Explicit branch names | |
# ===================== | |
branch OtherFile.read("./existing_file.txt"), | |
value_do: String.length, | |
exception_do: fn %{message: msg} -> msg end.() | |
# => 1000 | |
branch OtherFile.read("./missing.file"), | |
value_do: String.length, | |
exception_do: fn %{message: msg} -> msg end.() | |
#=> "error message" | |
# ========================== | |
# Convenient if/else variant | |
# ========================== | |
if_exception OtherFile.read("./existing.file"), do: fn %{message: msg} -> msg end.(), else: String.length | |
#=> 1000 | |
OtherFile.read("./missing.file") | |
|> if_exception do | |
fn %{message: msg} -> msg end.() | |
else | |
String.length | |
end | |
#=> "error message" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment