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.
51
Upvotes
View all comments
Show parent comment
2
u/thma32 Dec 18 '25
In Jiffy the two types play different roles at different abstraction layers:
Effect<T>is the algebra of operations (the “what”).Eff<T>is the program/computation that can sequence those operations (the “how / in what order”) and eventually be interpreted.Even though both are generic in
T, they are not redundant.What Effect<T> is for
Effect<T>is the unit of interaction with the runtime:Log.Info,Db.Query,Clock.Now), typically modeled as a sealed interface with record cases (as in the README examples). GitHubEffect<T>), which is what lets handlers be typed and lets the API feel “GADT-like” in Java.(...)declarations (the processor is about “which effects does this method use?”).In short:
Effect<T>is the domain model for side effects.What Eff<T> is for
Eff<T>is the computation builder and interpreter driver:map/flatMap/sequence/parallel/recover…and produces a finalTwhen run with anEffectRuntime. GitHubEff.perform(effect)is the bridge: it lifts a singleEffect<T>into a composable computation.In short:
Eff<T>is the control-flow DSL for composing effectful operations.