Closed dpsanders closed 4 years ago
Agreed, this would be cool to have, I will play with it, shouldn't be too hard.
Also, this is probably obvious, but in your original case you can already memoize the inner function:
obj = MyObject(@memoize function foo(x)
println("Computed $x")
x
end)
obj(3) # now memoized
This should work now on the latest version (0.1.2).
using Memoization
struct MyObject
f::Function
end
@memoize (x::MyObject)(n::Integer) = (x.f)(n)
f = MyObject(x->@show(x))
f(2)
f(2) # memoized
Different MyObject
instances will all have their own individual memoization caches. Let me know if you run into any issues!
I am trying to memoize a callable object, e.g.
But this doesn't seem to be implemented yet?