Last active
October 13, 2016 13:02
-
-
Save mpneuried/743bb259eb567a249e3c80efa376b27d to your computer and use it in GitHub Desktop.
Small example how to use with
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 WithTest do | |
def run do | |
with{:ok, a} <- fun("A"), | |
{:ok, b} <- fun("B"), | |
{:ok, c} <- fun("C") | |
do | |
{:ok, [a,b,c] } | |
else | |
{:error, err} -> | |
{:error, err} | |
end | |
end | |
def runError do | |
with{:ok, a} <- fun("A"), | |
{:ok, b} <- fun("B"), | |
{:ok, _x} <- fun(nil), | |
{:ok, c} <- fun("C") | |
do | |
{:ok, [a,b,c] } | |
else | |
{:error, err} -> | |
{:error, err} | |
end | |
end | |
defp fun( nil ) do | |
{:error, "NILL" } | |
end | |
defp fun( chr ) do | |
IO.puts( chr ) | |
{:ok, chr} | |
end | |
end | |
IO.inspect WithTest.run() | |
IO.inspect WithTest.runError() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment