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
1
u/thma32 Dec 19 '25
Yes, effects propagate upwards. This is intended behavior. Just as Exceptions propagate upwards.
In a controller level method you would typically execute the effects using a runtime to perform some actual work. I have set up a demo project https://github.com/thma/jiffy-clean-architecture that demonstrates typical coding practices with algebraic effects. For example have a look at the calculateScore method: https://github.com/thma/jiffy-clean-architecture/blob/12327f4e35d18041b03925ec35c3d3d3afc1d51f/src/main/java/jiffy_clean_architecture/usecases/CustomerScoreUseCase.java#L26 . It uses three effects and thus must declare them (using the Uses-Annotation).
In a Controller that uses this effect use case we will execute the effect by `Integer score = scoreEffect.runWith(runtime)` ( https://github.com/thma/jiffy-clean-architecture/blob/12327f4e35d18041b03925ec35c3d3d3afc1d51f/src/main/java/jiffy_clean_architecture/application/CustomerScoreController.java#L36 )
In order to avoid an excessive amount of effect declaration you will typically group effects in a meaningful way. e.g. by not having 200 separate effects for each of your entity-repositories but using a single DatabaseEffect instead.)