In “Elixir in Action”, there is an example about using pattern matching with the “with” special form:
with
{:ok, login} <- extract_login(user),
{:ok, email} <- extract_mail(user),
{:ok, pw} <- extract_pw(user)
do
{:ok, %{login: login, email: email, pw: pw}}
end
If each validation of user is successful, the “ok” tuple is returned. Otherwise, the first failing validation’s “error” tuple is returned.
But suppose I wanted to run all the validations, returning the same “ok” if they all pass, but returning a list of all the “error” tuples for all failing validations.
Is there an idiom for this in Elixir? afaik this is like an applicative functor.
This looks like what I was doing in Java, where functional programming idioms are at last available. I was hoping there were a macro or special form like with that might accomplish what that reduce is doing there. I’m still learning the bare basics. Thank you!