English3000
I am currently building an adapted API for Elixir…
And I just noticed how many functions of the same name Keyword and Map share.
What I’m wondering is why both the functions were put there instead of just in Enum?
My first guess would be: optimization.
And so my real question is from a design standpoint:
What determines whether a function should go in
Enum?
P.S. I know Enum.drop/2 exists–BUT, it actually does something different.
P.P.S. Whatever the answer is belongs in the docs.
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security











Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
English3000
An initial thought:
Imagine actually using
Enum.get/3While it’s doable, to me, it’s counter-intuitive – a dev wants to know what is the data structure being gotten from.By contrast,
Map.reduce/2-3andKeyword.reduce/2-3would suck because the operation has a different goal. It works on all entries of the collection; it doesn’t just fetch one.English3000
To add:
drop/2operates on some but not all entries.I think that’s the design distinction.
easco
Most of the contributions I’ve made to the Elixir core code have been contributions to the docs so once you get an answer, I encourage you to fork the Elixir core code and add what you need.
benwilson512
Keyword and Map are Enumerable in the sense that you can sensibly go through each entry one at a time. However they are also key value data structures. There will be a variety of same name functions related to the fact that they are both key value data structures that have nothing to do with iterating through collections.
Enum does not exist as a one stop shop of “every function that applies to multiple data structures”. It is specifically about manipulating Enumerable structures in their capacity of being enumerable.
eksperimental
If you want to create a function that covers Keyword.drop/2 and Map.drop/2 you would need to create something like Enum.drop_by_key/2. The thing is that it will not work for Enumerables that don’t have a key/value structure (as @benwilson512 said).
Remember maps are unordered data structures so many of the functions related to order in the Enum module will give unexpected results in maps and structs, such as Enum.drop/2 or Enum.take/2
eksperimental
You may want to have a look at this project of mine
https://github.com/eksperimental/elixir_inconsistencies
It may be useful for what you are working on
peerreynders
Apart from everything that has already been said, I also think it’s a “syntax vs semantics” issue - that is,
dropas a name plays the role of syntax while the module name adds context to define the desired semantics.Enum.drop/2operates in an enumerable fashion i.e. drop the first two elements.Enum.drop/2is not a good fit for Maps.Keyword.drop/2andMap.drop/2are keyed drops.Keyword.drop/2is expected to return KeywordsMap.drop/2is expected to return a MapSo from that perspective it is entirely appropriate that these implementations of
dropexist in different places (contexts).