3
votes

How can I do pattern matching against HashDict in Elixir? I can not find any decent information anywhere. So example I have is and it is bound to variable a:

#HashDict<[{"a", 1}, {"b", 2}]>

And lets say I want to get 2

I tried something like this to test a concept, but no luck:

[{"a",1}, {"b",val} = a

But I get: (MatchError) no match of right hand side value

Can someone help me with this?

1
Okay, I asked the same question on [elxir-talk google group][1] and as it turns out, there is no way I can do pattern matching on HashDict, but as of Elixir 0.13 map data type will be available and it can be patternmatched against. groups.google.com/forum/#!topic/elixir-lang-talk/UH_Iw8KC_ys - Janjiss

1 Answers

3
votes

You can't pattern match on a HashDict. In general, when you see something printed as #HashDict<...> it is exactly because its internal representation is "private". Maps are coming on Elixir 0.13 and they will support pattern matching (and other goodies).