Skip to content

Instantly share code, notes, and snippets.

@teamon
Created December 28, 2017 11:58
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 teamon/863bd2d72d96238b13fbe010cf075532 to your computer and use it in GitHub Desktop.
Save teamon/863bd2d72d96238b13fbe010cf075532 to your computer and use it in GitHub Desktop.
defmodule Test do
def run(x) do
with :error <- try_one(x),
:error <- try_two(x),
:error <- try_three(x) do
:error
end
end
defp try_one(1), do: {:ok, "one"}
defp try_one(_), do: :error
defp try_two(2), do: {:ok, "two"}
defp try_two(_), do: :error
defp try_three(3), do: {:ok, "three"}
defp try_three(_), do: :error
end
iex(5)> Test.run(1)
{:ok, "one"}
iex(6)> Test.run(2)
{:ok, "two"}
iex(7)> Test.run(3)
{:ok, "three"}
iex(8)> Test.run(4)
:error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment