# Recipe for custom array types with metadata bound to it

**URL:** https://discourse.julialang.org/t/recipe-for-custom-array-types-with-metadata-bound-to-it/18370
**Category:** General Usage
**Tags:** array, data\_structures
**Created:** [December 6, 2018, 12:11pm UTC](https://discourse.julialang.org/t/recipe-for-custom-array-types-with-metadata-bound-to-it/18370 "2018-12-06T12:11:33Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![sairus7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sairus7/32/10816_2.png) [@sairus7](https://discourse.julialang.org/u/sairus7)
#### Post date: [December 6, 2018, 12:11pm UTC](https://discourse.julialang.org/t/recipe-for-custom-array-types-with-metadata-bound-to-it/18370/1 "2018-12-06T12:11:33Z")

</div>

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](https://github.com/JuliaArrays/OffsetArrays.jl), I want to implement it for any AbstractArray subtype (simple array, [AxisArray](https://github.com/JuliaArrays/AxisArrays.jl), [StructArray](https://github.com/piever/StructArrays.jl), [CircularBuffer](https://github.com/JuliaCollections/DataStructures.jl/blob/master/src/circular_buffer.jl), etc.).

To do that, I should write something like OffsetArray [source](https://github.com/JuliaArrays/OffsetArrays.jl/blob/master/src/OffsetArrays.jl):

```
mutable struct MyArray{T,N,AA<:AbstractArray} <: AbstractArray{T,N}
    array::AA
    useful_data1::Int64
    useful_data2::String
    # and maybe another useful data fields
end

```

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](https://docs.julialang.org/en/v1/manual/interfaces/index.html#man-interface-array-1), 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?

---

<div class="post-metadata">

### Author: ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)
#### Post date: [December 6, 2018, 12:54pm UTC](https://discourse.julialang.org/t/recipe-for-custom-array-types-with-metadata-bound-to-it/18370/2 "2018-12-06T12:54:37Z")

</div>

This was discussed in [quite some detail here](https://discourse.julialang.org/t/composition-and-inheritance-the-julian-way/11231).
