Skip to main content
2 of 3
added 161 characters in body
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

To convert a Boolean test function such as PrimeQ or IntegerQ into a pattern one typically uses either Condition (/;) or PatternTest (?). There are specific strengths and purposes for each which are described in: Using a PatternTest versus a Condition for pattern matching.

Here is a simple and brief example of each:

Cases[Range@10, _?PrimeQ]
{2, 3, 5, 7}
Cases[Range@10, x_ /; PrimeQ[x]]
{2, 3, 5, 7}

Be aware that the PatternTest operator ? has unusually high binding power as seen in this table and with:

Precedence[PatternTest]
680.
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k