ets:match/2 with maps

Fred Youhanaie fly@REDACTED
Mon Apr 13 14:33:30 CEST 2020


Hi

I couldn't find any details on map based match patterns!

ETS allows maps as elements of the tuples.

ets:match/2 allows map based match patterns, and returns a result if the pattern map is a subset of the a matched element.

Is there a way of matching a tuple that is not a superset of the map pattern, i.e. only contains the keys in the map pattern?

To clarify, in the following example I would like ets:match/2 to only return [[gamma]].

Many thanks
Fred

1> T = ets:new(aaa, []).
#Ref<0.3164011085.1783496708.202417>

2> ets:insert(T, {alpha, #{one=>1, two=>2}}).
true

3> ets:insert(T, {beta, #{one=>11, two=>12}}).
true

4> ets:insert(T, {gamma, #{one=>11}}).
true

5> ets:tab2list(T).
[{gamma,#{one => 11}},
  {alpha,#{one => 1,two => 2}},
  {beta,#{one => 11,two => 12}}]

6> ets:match(T, {'$1', #{one=>11}}).
[[gamma],[beta]]


More information about the erlang-questions mailing list