Maps are hash tables (for 32+ elements) indexed by key. Therefore a lookup such as {1, 2, _}
, where we don’t fully have to key to hash, would require a linear traversal of all keys. In other words, maps are really not a good fit for the lookups you want to perform, regardless of Elixir having syntax for it or not.
Luckily, a relatively straight-forward solution is to nest your keys:
map = %{{1,2} => %{3 => :func_a},{2,3} => %{4 => :func_b}}
This way, if you want to lookup 1, 2, 3
, you do:
map[{1, 2}][3]
if you want any (or all) keys starting with {1, 2}
, then you do:
map[{1, 2}]