Skip to content

Instantly share code, notes, and snippets.

@mpneuried
Last active October 13, 2016 13:02
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 mpneuried/743bb259eb567a249e3c80efa376b27d to your computer and use it in GitHub Desktop.
Save mpneuried/743bb259eb567a249e3c80efa376b27d to your computer and use it in GitHub Desktop.
Small example how to use with
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