stevensonmt

stevensonmt

Issue with initializing nested MapSets

I ran into the following situation when trying to create a MapSet of MapSets yesterday. If you nest the MapSet.new() calls they get flattened. I don’t know if this is a bug or I am just unaware of the reason this should be the expected behavior. Does anyone have an explanation?

iex(1)> MapSet.new(MapSet.new([1,2]))
mapset<[1, 2]>
iex(2)> a = v(1)
mapset<[1, 2]>
iex(3)> MapSet.size(a)
2 # ← expected 1
iex(4)> MapSet.put(MapSet.new(), MapSet.new([1,2]))
mapset<[mapset<[1, 2]>]>
iex(5)> MapSet.size(v(4))
1 # ← this is what I wanted

Marked As Solved

eksperimental

eksperimental

If you want to create a map of one element, you wrap that element in a list like I did, but if Elixir would work as you suggest, if you want to create a map set of 5 elements, how would Elixir know that MapSet.new([1, 2, 3, 4, 5]) is a a map set of 5 elements or a map set of one element which is a list of length 5?

Also Liked

mudasobwa

mudasobwa

Creator of Cure

What do you mean if? MapSet.new/1 accepts enumerables only as it can be easily seen from the function spec.

Then it iterates through this Enumerable, dedups it and produces a MapSet from unique elements in this Enumerable.

Last Post!

stevensonmt

stevensonmt

I’m aware. The rest of the post includes “I think it’s a little odd that MapSet.new requires that the passed arg be enumerable.” @eksperimental explained why it obviously needs to be that way.

Where Next?

Popular in Questions Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
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
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
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 54092 488
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
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
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New

We're in Beta

About us Mission Statement