Let me start with an example:
data = Partition[RandomInteger[50, 40], 3];
s = {10, 50};
I'd like to choose the first element of each sublist subject to the selector "s". and then find the maximum of the list by the last element. one solution is using Table
Table[
MaximalBy[Select[data, #[[1]] <= s[[i]] &], Last]
, {i, Length[s]}]
but this requires an itrator (i).
The other solution is using an auxiliary function:
f[i_] = (#[[1]] <= s[[i]]) &;
MaximalBy[Select[data, f[#]], Last] & /@ Range[Length[s]]
I am wondering if there is a way to have one liner code ( by using MapThread for instance ).
Cases[data, {a_ /; a <= i, __}]
is slightly faster thanSelect[data, #[[1]] <= s[[i]] &]
in this case (roughly a factor of 2). $\endgroup$