Maybe something like this
bounds = {0, 2, 3.7, 5};
data = {{1, 1.1, 1}, {2, 1, 2}, {1, 2.3, 1}, {3, 2.2, 2}, {1, 3.5,
1}, {4, 3.6, 2}, {1, 4.2, 3}, {2, 4.4, 1}};
ineqFu[a_, b_, max_, expr_, data_] :=
If[
a == 0,
expr <= data[[b]]
,
If[
b == max,
data[[a]] < expr
,
data[[a]] < expr <= data[[b]]
]
]
max = Length@bounds + 1;
tokenizedIneqs =
ineqFu[##, max, token, bounds]r] & @@@
Partition[Range[0, max], 2, 1];
funkyTown =
Which @@@
(Function@
Evaluate[Riffle[tokenizedIneqs, Range[max]]] /.
token :> #[[2]]);
result = GatherBy[dataGatherBy[s, funkyTown];
We then have
result === output
True