These are a couple of small wrapper functions which I think would be very useful to developers. They create an idiomatic pathway for returning tuples from a pipeline.
The intended use case is in any module-level function that is entirely a pipeline, and where you would like to return the value that is the result of a pipeline of functions in tuple form, and
where you know the result of your pipeline will be either :ok or :error with certainty.
For a simplistic example, suppose I have a list of ids and I write a simple function to take the first id and return it in an
:ok tuple. Normally I would have to do something like this:
def return_first(id_list) do
first_id = id_list |> List.first!()
{:ok, first_id}
end
And that is okay, but somehow it doesn't feel like idiomatic
Elixir. Here you could just do this:
def return_first(id_list), do: id_list |> List.first!() |> put_ok()
To me, that feels a lot cleaner and clearer. It allows me to express my intention the in a way that feels closer to how Elixir
asks me to think about programming.
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/60d8054e-7f88-48ad-9ead-5ccc8ba1eccf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/0c1ced04-3f91-4108-859f-6a8490b3bab5%40googlegroups.com.