Skip to content

Instantly share code, notes, and snippets.

@expede
Last active August 31, 2016 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save expede/0ce06c184fc1bf030001f87e88611dc7 to your computer and use it in GitHub Desktop.
Save expede/0ce06c184fc1bf030001f87e88611dc7 to your computer and use it in GitHub Desktop.
use Exceptional
OtherFile.read("./existing_file.txt") ~> String.length
# 19
OtherFile.read("./missing.file") ~> String.length
# %OtherFile.NotFoundError{
# message: "File not found at ./missing.file",
# path: "./missing.file"
# }
OtherFile.read("./existing_file.txt")
|> exception_or_continue(String.length)
# 19
OtherFile.read("./existing_file.txt")
~> fn file ->
file
|> String.to_charlist
|> Enum.filter&(&1 == 101)
|> Enum.count
end.()
# 2
OtherFile.read("./missing.file")
~> fn file ->
file
|> String.to_charlist
|> Enum.filter&(&1 == 101)
|> Enum.count
end.()
# %OtherFile.NotFoundError{
# message: "File not found at ./missing.file",
# path: "./missing.file"
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment