Skip to content

Add memoizeSuccess functions to ZIO#10900

Open
kyri-petrou wants to merge 1 commit into
zio:series/2.xfrom
kyri-petrou:memoize-success
Open

Add memoizeSuccess functions to ZIO#10900
kyri-petrou wants to merge 1 commit into
zio:series/2.xfrom
kyri-petrou:memoize-success

Conversation

@kyri-petrou

Copy link
Copy Markdown
Contributor

Alternative implementation of #10791 that uses the same codepath as the new interruption handling

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Preview deployed to Netlify: https://pr-10900--zio-dev.netlify.app

* [[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]] =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))
     }
  )
}
  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants