Inspired by this topic I thought it might be interesting to talk about what pipelines we have encountered in the wild:
- Whenever you come across a piece of code featuring a pipeline that you think is cool or elegant, feel free to share.
- Also, feel free to share code snippets in which you feel that it might have been better not to use a pipeline but another abstraction.
- And feel free to politely comment on and discuss the submissions written by other posters. Do you agree/disagree? What would you have done differently?
with-chain can also be considered a kind of pipeline and be posted here, if you’d like.
All right, let’s start off:
This is a very simple example, part of the tensor library (for vectors, matrices and higher-dimension tensors) that I wrote a couple of years back.
What I like about this pipeline, is that is very clear to the reader what is going on. In most other languages, this would have to be written either in one line, or by using a temporary variable with probably a hard-to-choose name. The only other, non-pipeline approach I see, is to introduce an
as_transposed wrapper that takes a function pointer, and does both the transposition and back under the hood. Maybe that’s nice for some other languages, but in Elixir, where we have this potential to produce pipelines (aliteration intended), it is definitely overkill.