I was trying to implement what @mbauman suggested with respect to array reductions (sum, mean, etc.). Here is my idea at an implementation:
Base.getindex(A::Array, args::Union{T, Colon}...) where T<:Function = T(A, tuple(find((args .== T))...))
julia> A[sum,:] == sum(A, 1)
julia> A[:,mean] == mean(A, 2)
This has two problems:
-
Any Function could be used, not just reductions. It would be nice to be able to ‘subtype’ functions and dispatch on abstract functions like
Reduction
. I have not found any reference to abstract functions - what are your thoughts about that? -
Calling the function using
T()
does not work, as the type of the function is e.g.Base.#sum
and notBase.sum
. How can i call a function only having access to its type?