λ dmx-fun

Explicit types for failures, absence, and validation in Java.

dmx-fun is a Java library that makes failures, absence, and validation explicit in the type system. Instead of throwing exceptions or returning null, operations return values that encode both the happy path and the error case — composable via map and flatMap, pattern-matchable via sealed interfaces, and testable without mocks.

The core library has a single mandatory dependency: JSpecify for null-safety annotations. Everything else is optional.

Types

Eight composable types — each with a clear purpose, a consistent API, and a guide page.

Optional modules

Independent dependencies — add only what you need.

Installation

Available on Maven Central. See the Getting Started page for full coordinates.

Maven Central

Gradle
implementation("codes.domix:fun:LATEST_VERSION")
Maven
<dependency>
<groupId>codes.domix</groupId>
<artifactId>fun</artifactId>
<version>LATEST_VERSION</version>
</dependency>

Quick example

QuickExample.java
import dmx.fun.Option;
import dmx.fun.Try;
import java.util.function.Function;
public class QuickExample {
record User(String name, String email, String password) {
}
Function<String, Option<User>> findUser = email
-> Option.some(new User("User", email, "secret"));
private String getUserName(String email) {
// Handle options safely
return findUser.apply(email)
.map(User::name)
.getOrElse("Anonymous");
}
private void parseInt(String name) {
// Handle errors functionally
Try.of(() -> Integer.parseInt(name))
.recover(throwable -> {
System.out.println("Error parsing: " + throwable.getMessage());
return 0;
})
.onSuccess(System.out::println);
}
}

Ready to dive in?

The Developer Guide covers every type in depth — design rationale, every combinator, composition patterns, and pitfalls to avoid.