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

In this chapter, we looked at higher order functions, namely functions that take other functions as parameters, return a function as a result, or both.

We looked at the strategy pattern's Java implementation. We used Scala's higher order functions instead, to implement the algorithm encapsulation. Instead of Java classes implementing an interface, we passed in function literals. Then, we looked at three important patterns related to higher order functions.

We looked at Functors and then at the collection's map method. The second pattern was a Monad. We also looked at the flatMap method. The third pattern was monoids. In a related context, we also looked at foldLeft.

We applied the know-how to write an inverted index program. We looked at ...

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