Also thanks to this thread TIL that in Elixir small maps (<= 32
elements) automatically sort the keys by Erlang term order, while large maps (> 32
elements) do not!
In Elixir, the order of the keys is persisted if You have less than about 135 keys. I do not remember the exact number⊠nor where I learned that
Oh, thanks
intereseting fact, but âŠ
citation needed.
Hmm I only âlearnedâ by playing around in the repl. High probability that Iâm wrong
I checked, as I do remember it was my first question on the Elixir forum.
32 is the number I had in mind at that time, I guess I inflated the number a little bit
No, itâs me
Final and conclusive solution; always deleting the 1st pair:
new_map =
%{ânameâ => âfooâ, âaddressâ=> âbarâ}
|> Enum.into(%{}, fn
{ânameâ, v} -> {â1stâ, v}
other -> other
end)
|> Map.drop([â1stâ])
ps. try this at home but never at work.
At the moment of writing itâs true but one should not rely on it. So we may as well forget it as itâs an implementation detail that might change.
Still a fun Trivia fact to know thoughâŠfor as long as it lasts
If it wasnât piping a list into a Map
function this would be the definitive way to drop the 1st pair of a map
If performance is a concern and we donât want to create a full map from scratch, maybe we could do something like (disclaimer: I didnât benchmark):
{first_key, _, _} = map |> :maps.iterator() |> :maps.next()
Map.delete(map, first_key)
(âfirst_keyâ in the sense of whatever keys comes out first )
If you want the internet to respont, make an error - Elvis Presley
ps. quoting the brilliant and definitive answer, rewriting it using Enum.map/2 so you can say itâs wrong⊠it is Lousy. Jea Lousy. How would you feel if you liked a post and the author edited it and blamed you for something you did not?
Tag: satire
*respond
Haha!
Perhaps Elvis only left the building 'cos it had rubbish internet?
The proof was in the statement indeed. Suprised it took 2 hours
@sodapopcan
They are duplicated entries from database so theyâre pretty much the same except some properties are different so I can delete them based on logic
If some âthatâ properties are the same thenâŠ
I wanted to extract the first out, then delete the rest. I should have meant that in the beginning, sorry for the confusion guys. I wished I could have edited the post
Aha! This makes so much sense. Perhaps in your SQL query you could limit: 1
?
-duplicate suggestion-
Limiting in the database is much better as there is no need to send all records over the wire just to flush all but 1 of them.
Ecto returns lists of maps or structs so the take first element does not seem to be an issue. hd/1 would do.
Now I think I get the whole picture. The âtake the firstâ is less of an issue; the âhow to create the correct queryâ is.
As the application was progressing, it allowed users sign up with different methods as well as they can also be added manually through Phoenix UI database management app created by template
Now thatâs changed to signing up just by one method which is by domestic register only and people want to put a unique constraint on it
With every answer we get spoon fed another bite. Sooo curious about what the final question and answer will be. Stay tuned!