kelvinst

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

josevalim

Creator of Elixir

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

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

josevalim

Creator of Elixir

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

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

axelson

Scenic Core Team

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.

Where Next?

Popular in Libraries Top

New
scohen
Lexical Lexical is a next-generation language server for the Elixir programming language. Features Context aware code completion As-you...
New
Qqwy
TypeCheck: Fast and flexible runtime type-checking for your Elixir projects. Core ideas Type- and function specifications are const...
336 13801 100
New
dbern
I’m excited to announce that TaxJar has developed and open-sourced DateTimeParser. We developed it because we found a need to parse user ...
New
seancribbs
Today I released a new dialyzer Mix task as the dialyzex package! At the time we started writing this task, the existing dialyzer integra...
New
woylie
I released Doggo, a collection of unstyled Phoenix components. Features Unstyled Phoenix components. Storybook that can be added to...
New
nikokozak
Hello all, I’ve been working on Svonix - a library for quickly integrating Svelte components into Phoenix views. It’s a much-needed succ...
New
kelvinst
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 go...
New
woutdp
Hi! I wanted to introduce my latest project LiveSvelte. It allows you to render Svelte inside LiveView with end-to-end reactivity. It’s ...
New
maltoe
Hello! Came here to announce ChromicPDF, a pet project PDF generator I’ve been working on for the past few months. Why another PDF gener...
New

Other popular topics Top

belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New

Sub Categories:

We're in Beta

About us Mission Statement