[ANN] IndexFunArrays.jl - Fun with indices (and functions on them)

Thank you everyone, and my apologies for turning this thread into a tutorial. I do have one last question:

We know the field generator is a function so why give it a generic type parameter? So for example, instead of

struct IndexFunArray{T, N, F} <: AbstractArray{T, N} where {F}
    # stores the generator function to be applied to the indices. 
    generator::F
end

isn’t it better to do

struct IndexFunArray{T, N} <: AbstractArray{T, N}
    # stores the generator function to be applied to the indices. 
    generator::Function
end
1 Like

On the contrary: Function is an abstract type, while F is a type parameter which represents the concrete type of the generator function (each function has its own type).

1 Like

To be honest, I don’t know why we put the concrete type instead of function. But as @sijo mentioned, it might have some advantages when using concrete types in structs especially since we want the IndexFunArray to be fast.