Skip to content

Instantly share code, notes, and snippets.

@FScoward FScoward/script.exs
Created Dec 11, 2017

Embed
What would you like to do?
Elixirにおけるwithの挙動
defmodule Etc do
def hello do
IO.puts "Hello"
end
def return_ok do
{:ok, "ok"}
end
def return_err do
{:error, :eonet}
end
def return_err2 do
{:error, "error occured."}
end
def do_process do
with {:ok, content} <- return_ok(),
{:ok, content2} <- return_err(),
{:ok, content3} <- return_ok(),
{:ok, content4} <- return_err2()
do
IO.inspect content <> content2
else
{:error, :eonet} -> IO.inspect(:error)
{:error, content} -> IO.inspect(content)
end
end
end
Etc.hello
Etc.return_ok
Etc.return_err
Etc.do_process
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.