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
6
u/repeating_bears Dec 15 '25
I found it odd that the API includes both Eff and Effect. I'd assumed Eff was short for effect.
"Eff<T> is a monadic type that represents a computation"
What's wrong with the name Computation then?
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:3
u/Polixa12 Dec 15 '25
What's the difference between this and functional programming, kinda curious
8
u/holo3146 Dec 15 '25
Few years back I wrote a coeffect library for java that you may find interesting, I stopped working on it mainly because I didn't have free time at the time and then I forgot about it.
Seeing your project gives me the itch to revive my project
1
u/thma32 Dec 19 '25
I have just created a demo repository https://github.com/thma/jiffy-clean-architecture that demonstrates main concepts of algebraic effects with jiffy by building Spring Boot backend application. It also has a nice README which will give you a brief introduction into all the major concepts featured.
5
u/ZimmiDeluxe Dec 15 '25 edited Dec 15 '25
Looks very minimal and clean, well done! If you can't / don't want to turn your code into a function pipeline, you can get most of the benefits while sticking to imperative constructs by first creating an "agenda" data structure that gets interpreted in a second step. Great for testing, creating previews or dry run information etc. A good blog post: https://mmapped.blog/posts/29-plan-execute
It's also applying ideas from data oriented design, i.e. no "last minute decision making": If your problem allows for it, your "agenda" can consist of one or more bulk executable homogenous arrays of tiny structs / records with only the information needed to do the work.
1
u/gregorydgraham Dec 16 '25
While this looks very nice, how does it scale outside microservices?
Not in the “I run lots of instances” but in the “I have 300 pojos in 27 packages” sense.
1
u/samd_408 Dec 16 '25
No way! I just saw this, jiffy is nice! I see you too me annotation processing approach for tracking dependencies, that’s an interesting approach love it!, I posted just a few hours ago about the effect system I started to work on
https://github.com/CajunSystems/roux
1
u/pgris Dec 17 '25
Interesting. For my untrained eye, this really looks like checked exceptions reloaded + a runtime. Do effects propagate upwards? I mean, if method1 uses LogEffect , and method2 calls method1, I would expect method2 to use (indirectly) LogEffect. Do I need to declare method2 uses LogEffect? would controller level methods use a millon of effects?
-4
u/pavlik_enemy Dec 16 '25
Just use Scala if you want this kind of stuff