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.
Eithermonad which represents a value that can be either of two types.Trymonad which represents an operation that can either succeed or fail.EitherTmonad transformer which allows to encapsulate anEithermonad inside a CompletableFuture. This allows chaining and composing asynchronous computations that may fail, using functional programming principles.TryTmonad transformer which allows to encapsulate aTrymonad inside a CompletableFuture. This allows chaining and composing asynchronous computations that may fail, using functional programming principles.Validatedmonad which represents a value that can be either of two types, but it accumulates errors.Resourcewhich represents a resource that needs to be managed and closed after use for safe resource management.For Comprehensionwhich allows to chain and compose monads in a more readable way than using nested flatMaps.Lazymonad which represents a value that is computed lazily and memoized.SeqListmonad which represents a persistent and immutable list.Optionmonad which represents a value that may or may not be present which is an enhancement over the Java Optional.Readermonad which represents a computation that depends on a configuration.Writermonad which represents a computation that produces a log.IOmonad 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.10.0</version>
</dependency>- Introducing
TryTmonad with some examples TryT article - Explaining
SeqListmonad with some examples SeqList article - Explaining the
Lazymonad with some examples Lazy monad article - Explaining the
Optionmonad with some examples Optional monad article - Explaining the
Eithermonad 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.