3 ms·
> won't work if you (just) want conciseness I think Jose's example provides the best of both worlds, conciseness and readability. > you have more room to comm
by h0l0cube 4y ago
> won't work if you (just) want conciseness
I think Jose's example provides the best of both worlds, conciseness and readability.
> you have more room to comment what the intention of the code/call is
There's nothing stopping each pipe expression from having a comment of its own if you lean towards literate programming, or you feel that the pipe function + arguments begs further explanation to unfamiliar developers.
> you have room to handle / check for errors
You can pipe your results into a validation function. Ecto, the go-to database mapper, has exactly this pattern. Failing fast is idiomatic Erlang/Elixir (rather than let the process live on with corrupt state) which means if the validation fails, it ought to raise an exception so the external caller can fix their call/request, or if it's a bug, the developer can be alerted to fix the code.