loganhelms

loganhelms

Any resources to learn about memoization in Elixir?

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?

Most Liked

bryanhuntesl

bryanhuntesl

Trade off is memory consumption/local disk cache/staleness/invalidation

Sebb

Sebb

cjbottaro

cjbottaro

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
bryanhuntesl

bryanhuntesl

Where Next?

Popular in Chat/Questions Top

nur
https://e.planaria.network/stack.png https://e.planaria.network Build a NoSQL DB, Build a Relational SQL Database, Build a Graph Datab...
New
zeroexcuses
Besides Basic types - The Elixir programming language are there any other well recommended “elixir by example” style resources / books ? ...
New
lc0815
hello from a real frustrated newbe… I’m reading this article Full-Stack React With Phoenix (Chapter 3 | Introduction to Phoenix) by mich...
New
stevensonmt
I’d like to provide my review of the Elixir Course module from Groxio. I have some criticisms but I’d like to start with the positives. ...
New
asfand
Hi Everyone, I am a student and know basics of web development, used some php and ruby, but I am not an expert in any. I want to learn E...
New
New
marciol
Hey, I have very restricted resources and time so I’m trying to understand the best way to learn Liveview in terms of cost/time. The Pra...
New
pdgonzalez872
Hi! In my quest of becoming the best Elixir dev I can be, I saw one aspect in my career that I’d like to improve upon. This is language...
New
Fl4m3Ph03n1x
Background After following the communitiy suggestion, I bought the Elixir in Action 2nd Edition book and I am about to finish it now. I ...
New
koen_vb
Hi, I was looking for a pointer of how I could most easily start with phoenix regarding deploying it to something like linode or google c...
New

Other popular topics Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

We're in Beta

About us Mission Statement