OvermindDL1

OvermindDL1

Elixir Enum module usage

So I finally hopped on Slack (it really is like a worse gitter, not even code syntax highlighting, but that is for another post), and someone there said, and I quote:

Afaik people avoid Enum anyway

I rarely ever touch Enum

Pretty sure @david.antaramian also said at one point he rolls his own rather than Enum (although I might be wrong)

I think the general consensus is Enum until you know how to write Elixir comfortably, then roll your own as needed

because iteration is rarely ever generic

And that goes against everything I’ve been doing in Erlang for ten years.

Do people really not use the functional patterns in Elixir? Heck, I’ve found it beyond hard pressed to get anything self-written to perform faster than Enum.map (the example we were using) and even than it was less than 1% speed difference with a substantially larger amount of code.

Is this really true for people? I use Enum extensively (occasionally even drop down to the base erlang function just because familiarity and the arguments are in the right order (*cough*callback*funs*first*cough*), but even that is waning as Enum can do about everything). So someone saying that Enum is not generic enough for iteration is mind boggling to me…

If Enum (and other similar functional things like for-comprehensions) are not really used (outside my own work apparently?), do people really ‘roll their own function loops’ that often? Sure they are easy but they harder to follow than a simple Enum |> chain, harder to read, breaks the flow of data up significantly more, and slower in every benchmark we passed between compared to Enum on Erlang OTP 19 (the hand-rolled ones were from between 5% to 9% slower than the single-line Enum’s on my machine with repeated tests, Ubuntu 16.04 latest everything).

So yeah, do people really not use Enum/for-comprehensions and instead do it manually? I’ve been doing erlang for almost ten years and other functional languages for a decade before that and I would never consider doing such a thing, even if for a 10% speed bonus unless absolutely necessary, it is a code-reading-nightmare to me…

First Post!

sotojuan

sotojuan

I’ve never seen that either and to me it goes against Elixir having a strong standard library—reminds me of Node where people roll their own utilities because the STL sucks. I’ve never seen people use stuff manually and all learning materials I’ve seen advocate Enum.

Where Next?

Popular in Questions Top

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
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

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
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
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New

We're in Beta

About us Mission Statement