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 ...

Get Scala Functional Programming Patterns now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.