Hey, as you know I have lots of ideas. Most of my time takes normal job, so last time I’m quite busy. This night I can’t even sleep, because I thought about more and more enhancements for my ExApi
library.
This morning I found one example when I was looked at my old projects, snippets, plans and other related things.
defmodule Something do
def first(a, b), do: a + b
def second(tuple, b, c) when is_tuple(tuple) do
a = elem(tuple, 0)
second(a, b, c)
end
def second(a, b, c), do: {:ok, a + b + c, a, b, c}
def third(_a, _b), do: {:error, :fake}
end
defmodule Example do
use ExPipe
# 5 is initial data
# 10 is data before call function with error
# if not defined msg is nil
def_handle sample(5, 10, _error, msg), do: throw(msg)
# defining message is optional
def_msg sample(5, 10, {:error, atom}), do: Atom.to_string(atom)
def_process sample do
Something.first(&_, 2)
Something.second(1, &_, 2) # as second argument
Something.third(&_, 3) # function that stops processing
Something.second(&_, 2, 1) # function with custom ok tuple
elem(0) # by default as first argument, same as: $0
end
def_process sample2 do
Something.first(&_, 2)
Something.second(1, &_, 2) # as second argument
Something.second(&_, 2, 1) # function with custom ok tuple
elem(0) # by default as first argument, same as: $0
end
end
ExPipe.run(5, Example, :sample) # handled: throws "fake"
ExPipe.run(5, Example, :sample2) # result: 13
It was probably based on @OvermindDL1 example.
Since this is quite old idea I don’t expect much interest, but maybe someone would be interested in such library. Please let me know what do you think about it.