Chapter 10. Conclusion

I hope that you’ve found this book to be a helpful stepping-stone toward functional programming. Most important, I hope that it has demystified some of the concepts and shown how you might implement them without switching to a purely functional language.

I also hope that you can take some of the early concepts that might actually provide you the greatest benefit and apply those to your everyday job, helping you write less code while implementing more functionality.

From Imperative to Functional

At this point, you should have the knowledge and the understanding of how to transform your current imperative code into functional code. As you start your transition, you will want to break it down into steps. Let’s look at the transitional steps and recap how to implement those concepts:

  1. Introduce higher-order functions.
  2. Convert existing methods into pure functions.
  3. Convert loops over to recursive/tail-recursive methods (if possible).
  4. Convert mutable variables into immutable variables.
  5. Use pattern matching (if possible).

Introduce Higher-Order Functions

The first step to take is to introduce some higher-order functions, as you saw in Chapter 2. To accomplish this in Java, you either use pre-existing libraries such as Guava or create your own interface like the Function1 interface so that you can encapsulate functionality to be passed to another function.

As demonstrated in Chapter 2, you can also begin to convert to a language such as Groovy, which enables you to use ...

Get Becoming Functional now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.