View Source Memoize (memoize v1.4.3)
Module documentation for Memoize.
Summary
Functions
Define the memoized function.
Functions
Define the memoized function.
Below code:
defmemo foo(0, y) do
y
end
defmemo foo(x, y) when x == 1 do
y * z
end
defmemo foo(x, y, z \\ 0) when x == 2 do
y * z
end
is converted to:
def foo(t1, t2) do
Memoize.Cache.get_or_run({__MODULE__, :foo, [t1, t2]}, fn -> __foo_memoize(t1, t2) end)
end
def foo(t1, t2, t3) do
Memoize.Cache.get_or_run({__MODULE__, :foo, [t1, t2, t3]}, fn -> __foo_memoize(t1, t2, t3) end)
end
def __foo_memoize(0, y) do
y
end
def __foo_memoize(x, y) when x == 1 do
y * z
end
def __foo_memoize(x, y, z \\ 0) when x == 2 do
y * z
end