Currently pattern - matcher doesn' t go inside an Association
, and _Association
is an exception (head test). You can note, for example, that an Association
is AtomQ
(although this is only a consequence of that). So, if you want to use pure patterns, you're currently out of luck. But, you can use recursive patterns. In this case:
nestedAssocPattern = assoc_Association /; MemberQ[Values[assoc], _Association]
Now, you can test:
MatchQ[testAssoc, nestedAssocPattern]
(* True *)
MatchQ[<|1 -> 2|>, nestedAssocPattern]
(* False *)