Skip to main content
added 113 characters in body
Source Link
ybeltukov
  • 43.9k
  • 5
  • 109
  • 215

HoldPattern has attribute HoldAll

Attributes[HoldPattern]
(* {HoldAll, Protected} *)

So one can use the following injection

Cases[rules, HoldPattern[Alternatives@## -> _] & @@ targets]
(* {a -> 1, b -> 2} *)

P.S. Conceptually, HoldPattern is here the wrong tool for the job, even if this works. See Leonid's answer.

HoldPattern has attribute HoldAll

Attributes[HoldPattern]
(* {HoldAll, Protected} *)

So one can use the following injection

Cases[rules, HoldPattern[Alternatives@## -> _] & @@ targets]
(* {a -> 1, b -> 2} *)

HoldPattern has attribute HoldAll

Attributes[HoldPattern]
(* {HoldAll, Protected} *)

So one can use the following injection

Cases[rules, HoldPattern[Alternatives@## -> _] & @@ targets]
(* {a -> 1, b -> 2} *)

P.S. Conceptually, HoldPattern is here the wrong tool for the job, even if this works. See Leonid's answer.

Source Link
ybeltukov
  • 43.9k
  • 5
  • 109
  • 215

HoldPattern has attribute HoldAll

Attributes[HoldPattern]
(* {HoldAll, Protected} *)

So one can use the following injection

Cases[rules, HoldPattern[Alternatives@## -> _] & @@ targets]
(* {a -> 1, b -> 2} *)