Write a purely functional Bubble Sort application

Improve a classic, object-oriented sort application using Java's functional programming capabilities

Neal Ford coined the term functional thinking to describe the mental shift required from developers trained primarily in object-oriented programming, who want to integrate functional programming concepts and techniques into their practice. I applied this concept in my two-part tutorial, "Functional programming for Java developers." In Part 1, I introduced five functional programming techniques written in JavaScript, then in Part 2 we refactored those code examples using the equivalent Java code. Next, we refactored a number of those examples again, this time using functional programming language features introduced in Java 8.

Now I invite you to one last exercise in functional thinking, refactoring the Sort application from "Functional programming for Java developers, Part 2" to integrate a variety of functional techniques. One again we'll work through several iterations, improving the code as we go along.

Refactor #1: The classic bubble sort, with a functional twist

The original Sort application show below is far from functional. About the only thing functional about it is the sort() method's parameter list. Thanks to the passed comparator, that list indicates that sort() is a first-class function.

To continue reading this article register now

How to choose a low-code development platform