Functional Programming in Java 8

Functional Programming made easy!

Since Java 8 it is possible to use a more functional approach of programming in Java. Java isn’t a functional language, but sometimes a closure is just much better than an anonymous class. Some concepts of functional programming are still missing and if you are used to a functional style you often can’t express what you want because some things are just too cumbersome in Java.

I made a collection of helper classes and specialized functional types to help you write functional code in Java. This is more for educational purposes than for actual projects. There are not enough unit tests and Javadoc is mostly missing. But most methods are self explanatory if you know FP.

The project is hosted on github:

Some of the Features:

  • curry / uncurry / to [bi|tri|quad] fn
  • n-tuples (n ∈ [2,3,4])
  • partial application
  • zip / upzip
  • exception and null handling
    • sneaky exceptions
    • to null / default value
    • to “Maybe” (holds result or exception)
    • to Optional
    • or else …
  • cached functions
  • synchronized functions
  • sequences

Note: This doesn’t support recursive closures. You can combine it with “Recursive”, my other project for functional programming in Java.

Leave a Reply

Your email address will not be published. Required fields are marked *