kelvinst
Plumbing - useful functions to work with Elixir pipes
There was a feature proposal recently on Elixir core mailing list where an idea born. I got very interested in the idea, but it is not going to be added to the language core. So @josevalim suggested to create a plumbing package for it. For now, it has these functions:
[66, 67, 68]
|> pipe(&List.insert_at(&1, 0, 65)) # `pipe/2` sends the pipe subject to an anonymous function and returns its result
|> tee(&IO.puts/1) # `tee/2` sends the pipe subject to an anonymous function but returns the unmodified subject
ABCD
=> 'ABCD'
The plan is to add some more useful functions, ideas and PR’s are very welcome!
Most Liked
josevalim
My $.02, keep it simple.
Remember that every time someone proposes a new extension to the pipe operator, it is rejected because it will make the pipeline hard to read.
If I see the pipeline you posted above in actual code, I would have a hard time understanding what it does. Code should be optimized for reading.
kelvinst
Just explaining, the tee name comes from this: https://en.wikipedia.org/wiki/Tee_(command)
Since the pipe operator idea has the shell pipe as an inspiration, the tee name was adopted.
josevalim
Still, new functions should have their own value. We shouldn’t add them just for padding. We do want to avoid having a bunch of very small packages but in some cases, that’s all you need.
I agree that people can just copy those functions to their app and that is totally fine. The point of a package is to be useful, that doesn’t necessarily mean it has to be used. If the idea is pushed forward, then mission accomplished.
LostKobrakai
I’ve used the laravel collection package quite a bit and they named the functionality you named tee/2 tap, which I found quite nice: https://laravel.com/docs/5.5/collections#method-tap
axelson
Oooh, I like this idea! Definitely nicer in my opinion than resorting to macros that modify or enhance pipe’s directly. I love that these are just simple but useful functions that are very easy to reason about and discover. Can’t think of any new useful plumbing functions at the moment.
Although I may submit a docs PR or a PR that adds testing via stream_data.







