### Basic Examples

Basic Examples

In[]:=

LookupCases

[<|"A1"<|"B"1,"C"2|>,"A2"<|"B"3,"C"4|>|>,"B"]

In[]:=

{1,3}

Out[]=

Use the operator form:

["B"][<|"A1"<|"B"1,"C"2|>,"A2"<|"B"3,"C"4|>|>]

In[]:=

{1,3}

Out[]=

### Scope

Scope

In[]:=

An empty list is returned when no matches are found:

[<|"A"1|>,"B"]

In[]:=

{}

Out[]=

Looking up a delayed value causes the value to evaluate:

[<|"A"(Print[1];2)|>,"A"]

In[]:=

1

{2}

Out[]=

If the delayed value is in a non-matching key, evaluation does not occur:

[<|"A"1,"B"(Print[1];2)|>,"A"]

In[]:=

{1}

Out[]=

Don’t look up values on the top level association:

[<|"A"<|"A"1|>|>,"A",{1,Infinity}]

In[]:=

{1}

Out[]=

Only return the first match:

[<|"A1"<|"B"1,"C"2|>,"A2"<|"B"3,"C"4|>|>,"B",All,1]

In[]:=

{1}

Out[]=

LookupCases

[{<|"A"1|>,{"A"2}},"A"]

In[]:=

{1,2}

Out[]=

If the list contains other items besides rules, the match is not found:

[{"A"1,"B"},"A"]

In[]:=

{}

Out[]=

[{"A"1,"B"2},"A"]

In[]:=

{1}

Out[]=

Use a pattern for the key:

[<|"A1"<|"B1"1,"C1"2|>,"A2"<|"B2"3,"C2"4|>|>,_String?(StringMatchQ["B*"])]

In[]:=

{1,3}

Out[]=

### Possible Issues

Possible Issues

In[]:=

In a nested structure with the same key, both values are returned:

[<|"A"<|"A"1|>|>,"A"]

In[]:=

{1,A1}

Out[]=