Getindex for AbstractArray with Function

So you are looking for calculations on the indices, not on the values when selecting rows?

Maybe something like

m[foo.(axes(m, 1)), :]

for a function foo that returns a Bool. If you are working on the values, not the indices, then

m[foo.(m[:, 1]), :]

maybe with a @view in front.

I would not recommend overloading getindex for Array and Function, since that would be type piracy. Instead, you could make your own function, maybe

selectrows(f::Function, m::AbstractMatrix) = m[f.(axes(m, 1)), :]

and then, selectrows(>=(2), m), etc.

2 Likes