I'm trying to teach myself to use pure functions and slots as much as possible.
Here is my problem.
I have a list:
RandomSeed[314];
l = RandomInteger[{1, 10}, 20]
(*{3, 6, 1, 4, 4, 6, 1, 6, 3, 6, 8, 10, 8, 7, 5, 4, 8, 4, 4, 8}*)
Now I want to select all elements that equal 1 by using `Select`:
Select[l, # == 1 &]
(*{1, 1}*)
Then I want to get two lists, one with 8s and second with 1s:
test[p_] := p == # &;
Select[l, test[#]] & /@ {8, 1}
(*{{8, 8, 8, 8}, {1, 1}}*)
How can I do it without introducing `test[p_]`?
In other words I need `Select`'s second argument to depend on "another" slot `#`, not the one that will be substituted by list elements during iteration.