Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Moved to fork] ZIO module for interoperability with related libraries #42

Closed
wants to merge 22 commits into from

Conversation

ktonga
Copy link
Contributor

@ktonga ktonga commented Jun 14, 2018

-- Work In Progress --

The idea of this module is to enable code using ZIO IO to interact with other effect types from the Scala ecosystem such as Future and IO from cats-effect. Also define instances for TCs from scalaz-7.2

  • Create interop sbt module
  • Implement Future conversions
  • Scalaz 7.2 instances for IO
  • Cats Effect instances for IO
  • Add documentation

@ktonga ktonga added the WIP Work in progress label Jun 14, 2018
@ktonga ktonga self-assigned this Jun 14, 2018
@jdegoes
Copy link
Member

jdegoes commented Jun 17, 2018

Seems like a good idea. 👍


import scala.concurrent.Future

object future {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @jdegoes I could you a bit of early feedback on the API while I work on the impl + tests


val duHastMich: IO[Void, Future[Int]] = duHast.toFuture

val duHastMichGefragt: Future[Int] = unsafePerformIO(duHastMich)
Copy link
Member

Choose a reason for hiding this comment

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

RAMMSTEIN!!!!!!


import cats.effect.IO

object catz {
Copy link
Member

Choose a reason for hiding this comment

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

Hopefully this can be mostly grabbed from ioeffect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, i'll port it from there. And try to fix a bug that prevents sz IO to be used in fs2 😞

Copy link
Member

Choose a reason for hiding this comment

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

What bug is this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure, I have to reproduce what fs2 is doing with the Effect instance. Stream.join works with cats IO and monix Task but hangs with ioeffect IO.


}

object SampleUsage {
Copy link
Member

Choose a reason for hiding this comment

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

These examples should be moved, but I'm not sure where.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure 😄 It's only to demo the proposed API. I'll add this to the tests and then write some nice examples in the docs


object future {

implicit class IOObjOps(private val ioObj: IO.type) extends AnyVal {
Copy link
Member

Choose a reason for hiding this comment

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

I like this, if Scala doesn't have a problem with it. Would like to use the same technique in Scalaz 8 to support \/, Maybe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't (have a problem). That's the idea of the eager demo, to show that all this compiles and feels super ergonomic IMO.

object future {

implicit class IOObjOps(private val ioObj: IO.type) extends AnyVal {
def fromFuture[A](ftr: () => Future[A]): IO[Throwable, A] = {
Copy link
Member

Choose a reason for hiding this comment

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

Why not by-name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dunno, I don't like it since last time it kept me several nights debugging RTS

}

implicit class IOOps[E, A](private val io: IO[E, A]) extends AnyVal {
def toFuture(f: E => Throwable): IO[Void, Future[A]] = io.leftMap(f).toFuture
Copy link
Member

Choose a reason for hiding this comment

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

I think it should have a different name than the toFuture defined in IOThrowableOps. Maybe toFutureE.

Also, it would be customary to make this polymorphic in E2, rather than fixing to Void, although they are of course equivalent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted. I agree.

}

implicit class IOThrowableOps[A](private val io: IO[Throwable, A]) extends AnyVal {
def toFuture: IO[Void, Future[A]] = ???
Copy link
Member

Choose a reason for hiding this comment

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

It would be customary to make this polymorphic in E, rather than fixing to Void, although they are of course equivalent.


import scala.concurrent.Future

object future {
Copy link
Member

Choose a reason for hiding this comment

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

Should this be a package object?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What would be the benefit? Just asking.

case Success(a) => cb(ExitResult.Completed(a))
case Failure(t) => cb(ExitResult.Failed(t))
}
}
}
Copy link

@emilypi emilypi Jun 19, 2018

Choose a reason for hiding this comment

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

Do you want to thunk the Future in this case? on ioeffect I just pushed this PR in - i like the idea of having IO[Void, Future[A]] - then you can lift via point or now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I saw it, I commented precisely saying i don't like that 🙂

ktonga and others added 20 commits June 20, 2018 23:19
* convert into multi-project build

* move some settings to shared
* Backport latest changes from Z8

It includes changes from the following commits affecting the module
`effect` in the scalaz/scalaz repository:

- scalaz/scalaz@cf6ae80e3 fix bug in par and general code cleanup
- scalaz/scalaz@2f6c3dcae code cleanup
- scalaz/scalaz@a38e2b634 scalafmt
- scalaz/scalaz@d07918ba5 wrap up error model refactoring & update tests
- scalaz/scalaz@37c3e92a2 improved docs, function names, and bug fixes
- scalaz/scalaz@43e5f0a00 fixes #1665

* fixup! Backport latest changes from Z8
* version bumps

* use the same formatting as scalaz8

* fixup! use the same formatting as scalaz8
Include changes from following commits:

- scalaz/scalaz@c2f7e6dd8 Add Liskov for `IO.widen`
- scalaz/scalaz@3242958cf Use method value.
- scalaz/scalaz@456d5ba98 Do not use case classes for IO adt, since the feature is not used.
- scalaz/scalaz@043686dcd RTS: use eq/ne when comparing with null.
- scalaz/scalaz@de79b92fc RTS Stack: avoid array copy via nesting. removed unused peek().
- scalaz/scalaz@d9ce85e72 remove unused import
- scalaz/scalaz@0813ee457 remove try modify variants and add compareAndSet to IORef
- scalaz/scalaz@89e337fed code cleanup
- scalaz/scalaz@33ec2a23a scalafmt
- scalaz/scalaz@01ef0ce21 fix bug
scalaz/scalaz@0358c41bd Modify `SafeApp#run` to return `IO[Void, ExitStatus]`
scalaz/scalaz@42e7604dd Include scheduler in app shutdown
* MonadError instances close #49 #46

* cache the common usecase
@ktonga ktonga changed the title WIP: ZIO module for interoperability with related libraries [Moved to fork] ZIO module for interoperability with related libraries Jun 21, 2018
@ktonga
Copy link
Contributor Author

ktonga commented Jun 21, 2018

Closing to reopening it from a branch in my fork #58. If the PR is from a branch in the source repo it publishes snapshots on every push.

@ktonga ktonga closed this Jun 21, 2018
@ktonga ktonga deleted the interop branch June 21, 2018 13:06
iravid pushed a commit to iravid/zio that referenced this pull request Aug 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WIP Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants