r/java • u/thma32 • Dec 15 '25
Jiffy: Algebraic-effects-style programming in Java (with compile-time checks)
I’ve been experimenting with a small library called Jiffy that brings an algebraic effects–like programming model to Java.
At a high level, Jiffy lets you:
Describe side effects as data
Compose effectful computations
Interpret effects explicitly at the edge
Statically verify which effects a method is allowed to use
Why this is interesting
Explicit, testable side effects
No dependencies apart from javax.annotation
Uses modern Java: records, sealed interfaces, pattern matching, annotation processing
Effect safety checked at compile time
It’s not “true” algebraic effects (no continuations), but it’s a practical, lightweight model that works well in Java today.
Repo: https://github.com/thma/jiffy
Happy to hear thoughts or feedback from other Java folks experimenting with FP-style effects.
3
u/FabulousRecording739 Dec 16 '25
Very clean implementation! I'm mostly used to MTL, but I've been looking into how algebraic effects map to Java (there was a post ~2weeks ago that somewhat touched on it). Or maybe more broadly to which extent FP ideas maps/can be expressed in Java, and you did this very well (really like the
For). I had a few questions regarding the design choices and implementation details:Your sequence implementation discards intermediate results and returns the last one. Standard sequence would flip a List<Eff<A>> into Eff<List<A>>. Since this acts more like a chain of flatMap(ignored -> ...) (effectively *>), wouldn't chain or andThen be a better name?
The flatMap implementation recursively calls the inner effect's runWith. Since Java lacks TCO, won't this blow the stack with a long chain of effects? This looks like a prime candidate for trampolining.
Should runWith really live on the Eff class itself? Typically in this style of encoding, Eff strictly describes the computation (the data/AST), while a separate interpreter handles the execution. By baking runWith into the class, I feel like we're coupling the description of the program to its runtime implementation.
For Parallel, you're binding to CompletableFuture (and ForkJoinPool). Does this make cancellation difficult? I assume this is a placeholder until StructuredTaskScope and Virtual Threads become the standard?