Index rows of arbitrary dimensional array?

I have some code that receives vectors or matrices, and I would like to get certain rows while preserving the dimensionality of the input. E.g.

arr = [1, 2, 3]
mat = [1 2; 3 4; 5 6]

get_rows(arr, 2, 3) == [2, 3]
get_rows(mat, 2, 3) == [3 4; 5 6]

I haven’t been able to figure out how to do this with indexing – for example, arr[2:3, :] gets the right data but converts it to a matrix, and I wasn’t able to find anything in the documentation. Is there a way to slice over a single dimension while leaving the others intact?

julia> collect(selectdim(arr,1,2:3))
2-element Vector{Int64}:
 2
 3

julia> collect(selectdim(mat,1,2:3))
2×2 Matrix{Int64}:
 3  4
 5  6
3 Likes