Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kamilkloch
Copy link
Contributor

Added suspendTotal and suspendTotalWith, as discussed in #891. WIP.

@NeQuissimus NeQuissimus requested a review from jdegoes June 5, 2019 17:10
@NeQuissimus NeQuissimus force-pushed the master branch 2 times, most recently from 898f033 to 3cf511d Compare June 9, 2019 19:36
@kamilkloch kamilkloch marked this pull request as ready for review July 1, 2019 21:52
@jdegoes
Copy link
Member

jdegoes commented Jul 8, 2019

@kamilkloch It's not quite enough to use the types recommended in #891. Rather, if these are primitive operations baked into the interpreter, then we need to try / catch around them as done for ZIO.effect.

I recommend we motivate this by adding some tests. In particular, test that:

  • ZIO.effectSuspend(throw TestError).either.flatMap(_ must_=== TestError)
  • ZIO.effectSuspendWith(_ => throw TestError).either.flatMap(_ must_=== TestError)

@kamilkloch
Copy link
Contributor Author

I am not sure if the signatures are right (with regard to the error type). Current

effectSuspend(zio: => ZIO[R, E, A]): ZIO[R, E, A]

is as generic as possible, but effectSuspendhandles throwables, not generic Es.

On the other hand,

effectSuspend[R, A](task: => TaskR[R, A]): TaskR[R, A]

does not work for current FunctionIO.Impure implemenation (generic E):

private[zio] final class Impure[E, A, B](val apply0: A => B) extends FunctionIO[E, A, B] {
    val run: A => IO[E, B] = a =>
      IO.suspend {
        try IO.succeed[B](apply0(a))
        catch {
          case e: FunctionIOError[_] => IO.fail[E](e.unsafeCoerce[E])
        }
      }
  }

@jdegoes
Copy link
Member

jdegoes commented Jul 16, 2019

I am not sure if the signatures are right (with regard to the error type). Current

I think we can have, as you suggested, total variants that do not translate exceptions into typed error values. These can be generic for any E. Anything that catches a Throwable (the partial / non-total variants) will have to fix to Throwable.

@kamilkloch
Copy link
Contributor Author

I think we can have, as you suggested, total variants that do not translate exceptions into typed error values. These can be generic for any E. Anything that catches a Throwable (the partial / non-total variants) will have to fix to Throwable.

Thanks. Let me re-iterate to make sure I get it right. Current state in the PR:

effectSuspend(zio: => ZIO[R, E, A]): ZIO[R, E, A]
effectSuspendTotal(zio: => ZIO[R, Nothing, A]): ZIO[R, Nothing, A]

Desired state:

effectSuspend(taskr: => TaskR[R, A]): TaskR[R, A]
effectSuspendTotal(zio: => ZIO[R, E, A]): ZIO[R, E, A]

?

@jdegoes
Copy link
Member

jdegoes commented Jul 16, 2019

@kamilkloch Yes, and remember the partial variations should catch throw new Throwable (e.g.) and allow you to catchAll that error, whereas the total versions should not catch it.

Finally, remember the with variations that pass the Platform for low-level stuff...

@kamilkloch
Copy link
Contributor Author

effectSuspendTotal variations:

  • ZIO
    def effectSuspendTotal[R, E, A](zio: => ZIO[R, E, A]): ZIO[R, E, A]
  • RIO
    def effectSuspendTotal[R, A](rio: => RIO[R, A]): RIO[R, A]=> rio)
  • UIO
    def effectSuspendTotal[A](uio: => UIO[A]): UIO[A]
  • Task
    def effectSuspendTotal[A](task: => Task[A]): Task[A]

Only available in ZIO, RIO, Task:

def effectSuspend[R, A](rio: => RIO[R, A]): RIO[R, A]

@jdegoes
Copy link
Member

jdegoes commented Jul 20, 2019

@kamilkloch That looks correct to me! Don't forget the With variants that pass in the Platform.

And we need tests that:

  • *Total variants cannot be "caught" with catchAll
  • Partial variant (effectSuspend / effectSuspendWith) can be "caught" with catchAll

@kamilkloch
Copy link
Contributor Author

Don't forget the With variants that pass in the Platform.

It's already there :)

And we need tests that:

  • *Total variants cannot be "caught" with catchAll
  • Partial variant (effectSuspend / effectSuspendWith) can be "caught" with catchAll

Test for partial was there (unsafeRun(ZIO.effectSuspend[Any, Nothing](throw ExampleError).either) must_=== Left(ExampleError)). I just added the missing test for the total variant.

@kamilkloch
Copy link
Contributor Author

@jdegoes Do we miss anything? :)

Copy link
Member

@ghostdogpr ghostdogpr left a comment

Choose a reason for hiding this comment

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

The methods in ZIO, UIO, RIO, etc were sorted alphabetically recently. Can you move the new ones so that it stays sorted?

Apart from that, looks good to me.

Copy link
Member

@jdegoes jdegoes left a comment

Choose a reason for hiding this comment

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

Aside from alphabetical sorting, looks good to me. Thanks for your long work on this and high attention to detail!

@kamilkloch
Copy link
Contributor Author

@ghostdogpr @jdegoes methods are now sorted.

@jdegoes jdegoes merged commit 37e1a59 into zio:master Aug 4, 2019
@jdegoes
Copy link
Member

jdegoes commented Aug 4, 2019

giphy

ghostdogpr pushed a commit to ghostdogpr/scalaz-zio that referenced this pull request Aug 5, 2019
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.

3 participants