Would this be an idiomatic use of Tuple:
{:ok, fun()}
Specifically, I have this in my codebase:
case fetch_queued_proposal_logs(block_range) do
{:ok, events} ->
{:ok, {block_range, Enum.map(events, &proposal/1)}}
...
end
Thanks!
Would this be an idiomatic use of Tuple:
{:ok, fun()}
Specifically, I have this in my codebase:
case fetch_queued_proposal_logs(block_range) do
{:ok, events} ->
{:ok, {block_range, Enum.map(events, &proposal/1)}}
...
end
Thanks!
It’s not like that “idiomatic” prevents using some type in ok
tuple. Often, but again not required is to use String
or Atom
in error
tuple. Even in ecto
the {:error, changeset}
contains a list of errors with each item like: {:field_name, "error message"}
.
However ok
tuple is a successful return of some operation, so most likely the data it contains would be used many times. Therefore not only String
or Atom
are useful there, but also Map
, List
and other Enumerable
. There is nothing wrong with nested tuple, but don’t overuse that if there is no reason for it. Some people prefer 3-element tuple, but there is no standard for this or your way.
So your return is not common, but also not bad. Alternative way is to use 3-element tuple, but this is project / personal / team / company preference rather than a standard.
Thank you for the detailed response @Eiji.