malvinbozniak

malvinbozniak

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 !

Most Liked

NobbZ

NobbZ

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).

david_ex

david_ex

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 https://github.com/plataformatec/flow (there’s a video presentation linked in the README there).

Fl4m3Ph03n1x

Fl4m3Ph03n1x

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:

http://elixir-recipes.github.io/concurrency/parallel-map/

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:

Where Next?

Popular in Questions Top

lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
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
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New

Other popular topics Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
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
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
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
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
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
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New

We're in Beta

About us Mission Statement