I'm surprised that I can't find this question already, so perhaps I'm missing something obvious. I would like to take a list of associations and remove any with value "red"
. I ran into the following problem:
{<|8 -> 7|>, <|"a" -> "red", 6 -> 3|>} /. <|"a" -> "red", s___|> :> Nothing
outputs
{<|8 -> 7|>, <|"a" -> "red", 6 -> 3|>}
rather than my expected
{<|8 -> 7|>}
However,
{<|8 -> 7|>, <|"a" -> "red", 6 -> 3|>} /. <|"a" -> "red", 6 -> 3|> :> Nothing
works as expected, to give {<|8 -> 7|>}
. It's as if Association
is applying Verbatim
or something.
Why does the replacement fail here? Of course, the corresponding version using lists instead of associations works.
MatchQ[Association["a" -> "red", 6 -> 3], Association["a" -> "red", __]]
returnsFalse
. (For comparison, replacingAssociation[]
withList[]
givesTrue
.)