#development #elixir #reading-list

🔗 Elixir Task.async_stream/3
x.com

Honestly, these three lines of code should be all you need to show somebody the immense power of Elixir.

With just one function call, you can parallelise a task over all available CPUs. One!

1# Counts the characters in each word and returns the overall sum.
2#
3# Task.async_stream/3 runs as many tasks in parallel as you have schedulers.
4# This defaults to the number of available CPUs. Each task applies
5# the function to only one element and returns the result.
6["elixir", "is", "great"]
7|> Task.async_stream(fn word -> String.length(word) end)
8|> Enum.reduce(0, fn {:ok, count}, acc -> count + acc end)
continue reading on x.com

⚠️ This post links to an external website. ⚠️