Answer the question
In order to leave comments, you need to log in
Is there a good implementation of a lazy monad in Java?
Need a simple lazy evaluation library for java. Essentially one class. Initialized by the function T Lazy<T> of(Supplier<T> s)
Minimal interface - get method, on the first call starts the mentioned Supplier and caches its response. On the second call, it simply returns the value from the cache.
Is there something already ready?
PS Is it a monad at all?
Answer the question
In order to leave comments, you need to log in
Is it even a monad?
You can take Rx. There is such a thing as BehaviorSubject . All new subscribers will get the value from the "cache". When the data is updated, all subscribers will receive it.
The only problem is that the BehaviorSubject needs to be initialized with initial data.
But there are also so-called "cold" Observables in Rx. There, the calculation/action chain will not be called until there are no subscribers. Those. this is the kind of laziness that is needed. And most likely, there is a way to do both laziness and cache using Rx, I just don't know this library so well. But Google should know.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question