# Caching function values

**URL:** https://discourse.julialang.org/t/caching-function-values/2092
**Category:** General Usage
**Tags:** question
**Created:** [February 14, 2017, 12:39am UTC](https://discourse.julialang.org/t/caching-function-values/2092 "2017-02-14T00:39:10Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![lostella](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lostella/32/356_2.png) [@lostella](https://discourse.julialang.org/u/lostella)
#### Post date: [February 14, 2017, 12:39am UTC](https://discourse.julialang.org/t/caching-function-values/2092/1 "2017-02-14T00:39:10Z")

</div>

Hello,

This may be silly. I would like to understand whether this is a viable design pattern in Julia. I want to define a new type `GraphPoint <: AbstractArray` that joins together a point and a function value at that point (like a cache, to avoid re-evaluating a function if you will). I would do it pretty much like this:

```julia
immutable GraphPoint <: AbstractArray
  x::AbstractArray
  fx::Real
end

```

The idea is to have a function that uses this information to avoid computations, as in

```julia
function myFun(point::GraphPoint)
  return x.fx
end

function myFun(x::AbstractArray)
  # compute something with x
  return something
end

```

`GraphPoint` objects are created somewhere. It’s not relevant by whom or when. The point is, I would like to naturally extend all _other_ functions defined on `AbstractArray` to my new type `GraphPoint`, by simply redirecting them to the `x` field of the structure. Say, I would like to do matrix-vector products with `A::AbstractMatrix` and an object `point::GraphPoint` by doing `A*point.x`.

Is there a way to naturally extend _all_ functions defined on `AbstractArrat` to my new type `GraphPoint` in this sense?

Thank you.

---

_[View the full topic](https://discourse.julialang.org/t/caching-function-values/2092)._
