Add Async#syncStep - #2835
Conversation
| interpret(ioe, limit - 1) | ||
| .map { | ||
| case Left(_) => Left(io) | ||
| case Right((a, limit)) => Right((a.asRight[Throwable].asInstanceOf[B], limit)) |
There was a problem hiding this comment.
I couldn't figure out how to get the compiler to like this without the cast 😕
| override def syncStep[G[_], A](fa: IorT[F, L, A], limit: Int)( | ||
| implicit G: Sync[G]): G[Either[IorT[F, L, A], A]] = | ||
| G.map(F.syncStep[G, Ior[L, A]](fa.value, limit)) { | ||
| case Left(ior) => Left(IorT(ior)) | ||
| case Right(Ior.Right(a)) => Right(a) | ||
| case Right(right) => Left(IorT.fromIor(right)) | ||
| } |
There was a problem hiding this comment.
The transformers were quite interesting to implement :) the law is actually quite important here in guiding the right behavior: we can only return A if we pattern match the pure representation for the underlying datatype.
|
Will look at this in more detail in a bit. I want to leave it open for discussion for now though since this would be a pretty significant addition to |
|
I just added a slightly tweaked version of my law from above. I didn't realize |
Co-authored-by: Daniel Spiewak <djspiewak@gmail.com>
|
Approved once the above two minor nits are addressed. I think this is a good change overall. |
|
Oh actually, one further request: can you add this to |
| type G0[+A] = G[A @uncheckedVariance] // helps with type inference | ||
| def interpret[B](io: IO[B], limit: Int): G0[Either[IO[B], (B, Int)]] = { |
There was a problem hiding this comment.
Sorry, one last hack. I'd rather do this than the asInstanceOf below: type-erasure makes this okay, but unsafe casts are a footgun.
Thoughts?
There was a problem hiding this comment.
Nevermind, Scala 3 doesn't like this.
This reverts commit 0992325.
I tried doing this, but realized we basically can't.
In practice this is not a blocker since these can be implemented in user-land, but it is kind of annoying. Maybe could add them as syntax for |
Hmm, let's tackle this one in a follow up. We basically have to weigh whether a syntax enrichment in core is better or worse than a significantly-altered signature in std (e.g. taking a function of type |
It would have to be |
Takes the ideas from #1945 and #2613 and replays it for
Async[F]. I think this is the law we are aiming for:We should also consider adding
Dispatcher#unsafeRunSyncToFutureandDispatcher#unsafeRunSyncToPromiseto match the methods onIO. Slightly annoying is the need to explicitly pass alimitsince it cannot be retrieved from theIORuntimein this case.