Search code examples
clojureelixirlazy-evaluation

Lazy evaluation of expression in Elixir


I'm trying to figure out if there is a macro similar to delay in clojure to get a lazy expression/ variable that can be evaluated later.

The use case is a default value for Map.get/3, since the default value comes from a database call, I'd prefer it to be called only when it's needed.


Solution

  • Elixir's macro could be used for writing simple wrapper function for conditional evaluation. I've put one gist in the following, though it may be better/smarter way.

    https://gist.github.com/parroty/98a68f2e8a735434bd60