Created
February 14, 2018 06:46
-
-
Save allenyang79/c7ade77bf12752d598bc67f5136614f5 to your computer and use it in GitHub Desktop.
test elixir `with` syntax #elixir
This file contains hidden or 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 Foo do | |
| def foo(a,b) do | |
| with {:ok, dob} <- a, | |
| {:ok, name} <- b | |
| do | |
| %{dob: dob, name: name} | |
| else | |
| # nil -> {:error, ...} an example that we can match here too | |
| # err -> err | |
| _ -> :err | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment