O'Reilly logo

Scala Functional Programming Patterns by Atul S. Khot

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Summary

Lazy acquisition is a pretty commonly used pattern. The proxy design pattern is a nice example of Lazy Acquisition. ORM frameworks like Hibernate use proxies for lazy loading. Scala pushes the envelope by providing lazy vals and streams, which provide for on-demand computation, using thunks. Memoization is a related pattern to avoid computing the same value again. Instead, the value is cached. Java's autoboxing classes use memoization to conserve memory. Scala's streams use memoization and strike a balance between on-demand computation and memoization. Call by name is another powerful technique for delayed evaluation of code.

Let's now try mixing in some traits to our bag of Scala techniques in next chapters. Traits are Java interfaces ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required