We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
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!
# Counts the characters in each word and returns the overall sum. # # Task.async_stream/3 runs as many tasks in parallel as you have schedulers. # This defaults to the number of available CPUs. Each task applies # the function to only one element and returns the result. ["elixir", "is", "great"] |> Task.async_stream(fn word -> String.length(word) end) |> Enum.reduce(0, fn {:ok, count}, acc -> count + acc end)
continue reading on x.com
⚠️ This post links to an external website. ⚠️
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.