2

I'd like to know how to define logical conditions to manipulate them. For example, say I have a list list of pairs of numbers, and I want to Select those which satisfy some condition

cond = #[[1]] > 0 &;

Then I just have to evaluate Select[list, cond]and it works. But if I have several conditions

cond1 = #[[1]] > 0 &; cond2 = #[[2]] > 0 &;

then both Select[list, cond1 && cond2] and Select[list, cond1 || cond2] always give an empty list. How do I have to combine the conditions inside Select[ ] so that it understands the logical connection between them ( AND or OR)?

MBolin
  • 257
  • 1
  • 6

1 Answers1

1

You could do:

Select[list, Through @* And[cond1, cond2]]

For example:

Select[Range[10], Through @* And[PrimeQ,EvenQ]]

{2}

Carl Woll
  • 130,679
  • 6
  • 243
  • 355