Skip to content

Conversation

@cornerman
Copy link
Owner

@cornerman cornerman commented Mar 19, 2022

This is the best I could come up with for cats-effect 3 without totally rewriting the whole Observable interface.

I think, a potentially cleaner approach would be to move the effect type into the Observable trait like Observable[F[_], A]. But that has other disadvantages - it becomes difficult to mix different effect types and it adds noise by introducing a type parameter everywhere.

Changes

Functions like fromAsync[F[_]], mapAsync[F[_]], etc. do not just need an Effect[F] instance, but actually need a Dispatcher[F] or IORuntime now. Therefore, we have invented our own replacement unlawful typeclass for effect: RunEffect and RunSyncEffect (this is similar to what scalajs-react does). Coming with instances for IO and SyncIO. You can also create one for Async or with a Dispatcher. Also adding a module for zio Task support.

  • fromEffect[F[_]], mapEffect[F[_]] which takes a RunEffectF] implicitly

Thereby fromSync[F[_]] and mapSync[F[_]] are also deprecated in favor of fromEffect/mapEffect.

Furthermore, we have renamed all side-effecting functions like subscribe, onNext, onError, cancel to unsafeSubscribe, unsafeOnNext, unsafeOnError and unsafeCancel. I know, the names are not that beautiful, but I want to make sure that users know that these method actually are a side-effect. The old ones are now deprecated. There also now exist referential transparent versions of these: subscribeF[F[_]:Sync], subscribeIO, subscribeSyncIO and so on.

We had to drop support for monix for now, because it does not support cats-effect 3 yet. I have commented it out for now.

I also took the liberty to remove the types CreateSubject, CreateProSubject. The only use-case was with monix in outwatch and will now be removed.

Feedback is welcome! @TobiasRoland @fdietze What do you think?

Fixes #165
Fixes #5

@cornerman
Copy link
Owner Author

Realistically, people will probably mostly use fromIO / mapIO variants.

The methods returning resources are the "correct" implementation for the current interface but feel unergonomic.

The methods taking an implicit dispatcher is a pattern i saw in https://github.com/zio/interop-cats. It's just that you normally do not have a dispatcher implicitly - cats effect actively advises against it.

Possibly makes sense to have extension methods for specific libraries like zio or monix to make it work better.

@cornerman
Copy link
Owner Author

Another question: should we just use IORuntime.global as we do now (equivalent of what we did in cats effect 2). Or should we pass it in implicitly?

@cornerman cornerman force-pushed the cats-effect-3 branch 4 times, most recently from 88b3b25 to f7b9ab2 Compare March 21, 2022 23:52
@cornerman
Copy link
Owner Author

If you have an IORuntime in scope now, it will be picked up. Not the most reliable way, but the best we can do for now without requiring one.

@cornerman cornerman requested a review from fdietze March 24, 2022 17:28
@cornerman cornerman merged commit 8500dc7 into master Mar 27, 2022
@cornerman cornerman deleted the cats-effect-3 branch March 27, 2022 14:32
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.

CE3 Referential transparent API

2 participants