A Java 8 annotation processor for deriving algebraic data type constructors, pattern matching, folds, optics, and typeclasses.
Derive4J is a Java annotation processor that automatically generates boilerplate code for algebraic data types, enabling functional programming constructs like pattern matching, folds, optics, and typeclass derivations. It solves the verbosity of implementing ADTs manually in Java, providing compile-time safety and reducing repetitive code.
Java developers adopting functional programming patterns, library authors building type-safe APIs, and teams implementing domain-specific languages or complex immutable data models.
Developers choose Derive4J for its comprehensive feature set, compile-time safety, and seamless integration with functional libraries like Functional Java and Vavr, offering a Haskell-like experience in Java without runtime overhead.
Java 8 annotation processor and framework for deriving algebraic data types constructors, pattern-matching, folds, optics and typeclasses.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Provides exhaustiveness checks in pattern matching, as shown in the HTTP request example where all cases (GET, DELETE, PUT, POST) must be handled, preventing runtime errors.
Automates laziness, optics, catamorphisms, and typeclass derivations, reducing manual coding for complex FP constructs like in the Expression DSL example.
Supports flavours for Functional Java, Vavr, and others, allowing seamless use of their Option types and optics, as mentioned in the optics section with FJ flavour.
Generates constructors, getters, setters, and pattern matching code automatically, as demonstrated with the Request class, eliminating verbose visitor implementations.
Avoids implementing equals/hashCode by default to preserve parametricity, forcing developers to add abstract methods or use typeclasses, which complicates interoperability with standard Java tools.
Requires familiarity with algebraic data types, visitor patterns, and FP concepts, making it less accessible for teams new to functional programming, as cautioned in the README's 'Further reading' section.
As an annotation processor, it adds compilation overhead and setup steps, especially in incremental builds or with tools like Maven/Gradle, which can slow down development cycles.
Full features like optics or GADTs depend on external libraries (e.g., derive4j/hkt for TypeEq), creating vendor lock-in and potential compatibility issues with non-FP projects.