Zach is currently looking for his next challenge! Reach out if you think he'll be a good fit for your organization.
Zach is a software developer who has worked on a range of projects, with expertise in Ruby/Rails and MySQL performance. He also tinkers with other languages in his free time (currently Go, Haskell, Scala, Clojure, and Rust).
He knows how to laugh at himself and loves to ship software. He is a father of two wonderful kids and a husband to a fantastic wife.
In Ruby, it’s common to use instance variables and conditional assignment to
to concisely memoize expensive
operations.
You could reuse the same of strategy of detecting nil/null and conditionally
evaluating the result. However Scala has lazy evaluation built in. So you could
write the following:
When MemoizeSomething is initialized, it won’t evaluate somethingExpensive
right away, but the first time that variable is requested it will fully evaluate
it.
If you’re not a fan of the closure above, you could also use a separate method: