Created
December 28, 2017 11:58
-
-
Save teamon/863bd2d72d96238b13fbe010cf075532 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
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