A while back, I read a great book by Luis Atencio titled, Functional Programming in JavaScript. In section 7.3, he discusses memoization (an optimization technique for caching output values for pure functions for optimization).
If this is already part of Elixir, could someone point me to where I can learn more about it?
If it is not part of Elixir, is there a discussion for its value and tradeoffs?
3 Likes
Trade off is memory consumption/local disk cache/staleness/invalidation
5 Likes
You don’t even need a process to manage state for memoization. Just need to change your API a little bit.
Stateful Ruby…
class Foo
def blah
@blah ||= calc_blah()
end
end
Stateless Elixir…
module Foo do
def blah(obj) do
if obj.blah do
{obj.blah, obj}
else
blah = calc_blah(obj)
{blah, %{obj | blah: blah}}
end
end
end
3 Likes