Add memoizeSuccess functions to ZIO#10900
Open
kyri-petrou wants to merge 1 commit into
Open
Conversation
Contributor
|
🚀 Preview deployed to Netlify: https://pr-10900--zio-dev.netlify.app |
vagroz
reviewed
May 11, 2026
| * [[memoize]] For a variant that caches the result of the effect after its | ||
| * first execution, regardless of success or failure. | ||
| */ | ||
| final def memoizeSuccess(implicit trace: Trace): UIO[ZIO[R, E, A]] = |
Contributor
There was a problem hiding this comment.
Can we create a helper that flattens the environment from the inner effect into the outer one?
like this:
ZIO[R1, E1, ZIO[R2, E2, A]] => ZIO[R1 & R2, E1, IO[E2, A]]
Of course, this is unrelated to the current PR, but it would simplify writing this kind of code quite a bit:
object A{
val make: RIO[B & Scope, A] = ???
}
class MyService(dep: Task[A]) { ... }
object MyService {
val layer: = ZLayer.scoped(
ZIO.environmentWith[B & Scope]{ r =>
A.make.memoizeSuccess.map { aRio =>
new MyService(aRio.provideEnvironment(r))
}
)
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Alternative implementation of #10791 that uses the same codepath as the new interruption handling