KeyValuePattern

KeyValuePattern[{patt1,}]

is a pattern object that represents an association or list of rules that includes elements matching each of the patti.

Details

  • The patti are often of the form keyivali but can be any pattern.
  • Elements matching the patti can appear in any order in the association or list of rules.
  • The patti are matched in the order they appear.
  • Each of the patti is taken to match a different element of the association or list of rules.
  • For a single pattern patt, KeyValuePattern[patt] is equivalent to KeyValuePattern[{patt}].
  • KeyValuePattern[{}] matches any association or list of rules.

Examples

open allclose all

Basic Examples  (3)

KeyValuePattern lets you match any element in an association:

In[1]:=
Click for copyable input
Out[1]=

It also works on lists of rules:

In[2]:=
Click for copyable input
Out[2]=

KeyValuePattern matches elements that appear anywhere in an association:

In[1]:=
Click for copyable input
Out[1]=

Match any association with two entries:

In[1]:=
Click for copyable input
Out[1]=

Scope  (6)

Applications  (1)

Properties & Relations  (3)

Possible Issues  (3)

See Also

Association  OptionsPattern  PatternSequence  OrderlessPatternSequence

Tutorials

Introduced in 2016
(10.4)