# Avoiding rewriting accessor methods for new composite types with similar fields

**URL:** <https://discourse.julialang.org/t/avoiding-rewriting-accessor-methods-for-new-composite-types-with-similar-fields/59772>\
**Category:** General Usage\
**Created:** [April 22, 2021, 2:39am UTC](https://discourse.julialang.org/t/avoiding-rewriting-accessor-methods-for-new-composite-types-with-similar-fields/59772 "2021-04-22T02:39:26Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [April 22, 2021, 1:01pm UTC](https://discourse.julialang.org/t/avoiding-rewriting-accessor-methods-for-new-composite-types-with-similar-fields/59772/2 "2021-04-22T13:01:57Z")

</div>

`Lazy.jl` has a @forward macro that simplifies this:

> [@Confused with type definition](https://discourse.julialang.org/t/confused-with-type-definition/53115/13):
>
> I am kinda surprised nobody mentioned [Lazy.jl](https://github.com/MikeInnes/Lazy.jl) and its macro [@forward](https://github.com/MikeInnes/Lazy.jl/blob/master/src/macros.jl#L276). Basically you can do: import Base: length, getindex, setindex using Lazy: @forward struct MyVec \<: AbstractVector{Float64} v::Vector{Float64} # same as Array{Float64, 1} end @forward MyVec.v Base.size, Base.getindex, Base.setindex! For all function you just delegate to the field.

---

_[View the full topic](https://discourse.julialang.org/t/avoiding-rewriting-accessor-methods-for-new-composite-types-with-similar-fields/59772)._
