Do piped functions run in parallel

Hi there !
I’m Malvin and I’m new to FP in general.
I’ve started reading about FP and Elixir, and I found them so exciting :slight_smile:

Well, my first question for you is what the subject states.
When I chain functions in a pipe, do them run in parallel (like Unix piped commands do) ?
Or do I need to use specific syntax to do it so ?

Thanks & regards !

The functions are called sequentially, they might trigger computations that happen concurrently or lazily…

Always remember that a |> f() just is a macro that expands into f(a).


As @NobbZ said, piping in Elixir is just syntactic sugar for readability. If you want to distribute work across CPU cores, you’ll want to look at something like (there’s a video presentation linked in the README there).


And flow (as recommended by @david_ex) builds on top of GenStage. Depending on the complexity of what you are trying to achieve, a more barebones approach (using GenStage) may be worthwhile when compared to the more nuclear one using Flow… or Broadway which is also really nice but attacks a different use case (more focused on metrics rather than pure data).

And if you really enjoy concurrent programming, you may want to keep your heads up for Hastega’s successor.

Overall, there are a multitude of options when you want concurrency in Elixir. But since you are starting (welcome, btw!) perhaps a concurrent map elixir recipe will be more suited for your needs:

I still remember when Joe (God rest his soul in peace) introduced pmap in his erlang classes. I was blown away by it’s simplicity, I hope you are too :stuck_out_tongue:


Very valuable answers :slight_smile:
Thank you all partners !