This library aims to provide a set of utilities to help with functional programming in Java.
It is inspired by the functional programming libraries in other languages, such as Scala, Haskell, and Clojure and aims to be a zero-dependencies library.
It is also inspired by libraries such as Vavr
or Cyclops
. But these have issues such as:
- They do not seem to be maintained anymore.
- They are not zero-dependencies libraries.
- They have a big learning curve.
It is a small library, and it will never compete the big ones, but it can be useful for those that would like to remain lean.
Either
monad which represents a value that can be either of two types.Try
monad which represents an operation that can either succeed or fail.EitherT
monad transformer which allows to encapsulate anEither
monad inside a CompletableFuture. This allows chaining and composing asynchronous computations that may fail, using functional programming principles.TryT
monad transformer which allows to encapsulate aTry
monad inside a CompletableFuture. This allows chaining and composing asynchronous computations that may fail, using functional programming principles.Validated
monad which represents a value that can be either of two types, but it accumulates errors.Resource
which represents a resource that needs to be managed and closed after use for safe resource management.For Comprehension
which allows to chain and compose monads in a more readable way than using nested flatMaps.Lazy
monad which represents a value that is computed lazily and memoized.SeqList
monad which represents a persistent and immutable list.Option
monad which represents a value that may or may not be present which is an enhancement over the Java Optional.Reader
monad which represents a computation that depends on a configuration.Writer
monad which represents a computation that produces a log.IO
monad which represents a computation that performs side effects which is lazy.
To add the library to your project, you need to add the jitpack repository to your build file.
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Then, you can add the dependency to your project.
<dependency>
<groupId>com.github.VassilisSoum</groupId>
<artifactId>FunctionalUtils</artifactId>
<version>2.8.0</version>
</dependency>
- Introducing
TryT
monad with some examples TryT article - Explaining
SeqList
monad with some examples SeqList article - Explaining the
Lazy
monad with some examples Lazy monad article - Explaining the
Option
monad with some examples Optional monad article - Explaining the
Either
monad with some examples Either monad article
- Persistent List monad implementation equivalent to ArrayList but different from the Java collections to be truly immutable and performant using structural sharing.
- Persistent HashMap/HashSet monad implementation but different from the Java collections to be truly immutable and performant using structural sharing.