# Creating a specialisation of a built-in type?

**URL:** <https://discourse.julialang.org/t/creating-a-specialisation-of-a-built-in-type/48119>\
**Category:** New to Julia\
**Created:** [October 10, 2020, 5:26pm UTC](https://discourse.julialang.org/t/creating-a-specialisation-of-a-built-in-type/48119 "2020-10-10T17:26:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![foobar](https://avatars.discourse-cdn.com/v4/letter/f/f19dbf/32.png) [@foobar](https://discourse.julialang.org/u/foobar)\
**Post date:** [October 10, 2020, 5:26pm UTC](https://discourse.julialang.org/t/creating-a-specialisation-of-a-built-in-type/48119/1 "2020-10-10T17:26:57Z")

</div>

Hi,  
I want to work through the “Ray Tracer Challenge” book whilst learning julia.

To do so I’d like to achieve the following:

- have a MyTuple type that acts exactly as regular tuples do
- be able to redefine operators for MyTuple as needed, i.e. have Base.(==)(a::MyTuple, b::MyTuple) that acts a little different from regular == as motivated by the book

In other words, unless I define specialized operators and methods for MyTuple, I want all built-in operators and methods for Tuple to be used for MyTuple.

How would you achieve that in julia?

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [October 10, 2020, 5:51pm UTC](https://discourse.julialang.org/t/creating-a-specialisation-of-a-built-in-type/48119/2 "2020-10-10T17:51:25Z")

</div>

Basically: encapsulation. Create a `struct` containing your concrete `Tuple` type as a member, and then forward the methods you want to apply directly to the inner tuple. You can use `@forward` from Lazy.jl to make that easier.

There is no way to automatically apply “all” functions that act on Tuple to your own type–you will need to explicitly `@forward` or implement the ones you want. This sounds inconvenient, but I suspect there are relatively few methods you’ll actually need (`getindex` and `size` might be enough).
