Selecting lists where all are prime
This is a perfect use case for AllTrue
:
Select[t, AllTrue[PrimeQ]]
(* {{7, 13, 19}, {37, 73, 109}} *)
Alternatively, you should specify the pattern you actually want in Cases
:
Cases[t, {___?PrimeQ}]
(* {{7, 13, 19}, {37, 73, 109}} *)
If for some reason you really want a function you can Map
over the list to do what you want, you'll need to use Replace
in concert with the special symbol Nothing
:
Map[Replace[Except[{___?PrimeQ}] -> Nothing], t]
(* {{7, 13, 19}, {37, 73, 109}} *)
Pick[t, And @@@ PrimeQ @ t]
{{7, 13, 19}, {37, 73, 109}}
Either of these takes advantage of the fact that PrimeQ
automatically threads over lists:
Select[t, Apply[And]@*PrimeQ]
Select[t, And @@ PrimeQ[#] &]
(* Out: {7, 13, 19}, {37, 73, 109} *)