Recipe for custom array types with metadata bound to it

I want to implement custom array type with some additional fields to store useful metadata information bound to that array. But, similar to OffsetArrays.jl, I want to implement it for any AbstractArray subtype (simple array, AxisArray, StructArray, CircularBuffer, etc.).

To do that, I should write something like OffsetArray source:

mutable struct MyArray{T,N,AA<:AbstractArray} <: AbstractArray{T,N}
    # and maybe another useful data fields

Then I should reimplemet all AbstractArray methods in the form that:

size(X::MyArray) = size(X.array)
getindex(X::MyArray, i) = getindex(X.array, i)

And so on for every abstract array interface method, right? Or even for some other interfaces too (indexing, iterator)?

It would be simpler if I had some common recipe to do that in one row for any particular custom array type with different metadata fields, without having to rewrite all those methods. How can I do that?

1 Like

This was discussed in quite some detail here.

1 Like