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

Consider changing return type of `Cancelable.empty` from `Empty` back to `Cancelable` #773

Closed
sirmax opened this issue Nov 8, 2018 · 5 comments

Comments

Projects
None yet
2 participants
@sirmax
Copy link

commented Nov 8, 2018

3.0.0-RC1 had Cancelable.empty return Cancelable, 3.0.0-RC2 changed the return type to Empty.

This change breaks compilation of fold-like code, for example this compiles with 3.0.0-RC1

Observable
  .intervalAtFixedRate(…)
  .scan(Cancelable.empty -> …) {
    case ((prevKillSwitch, _), i) =>
      prevKillSwitch.cancel()
      newKillSwitch = BooleanCancelable()
      newKillSwitch -> …
  }

but with 3.0.0-RC2 scalac complains that the expression in scan does not conform to expected type (Cancelable.Empty, …).

Using Cancelable() instead of Cancelable.empty makes it compile again, but it would be nice to have empty also work since it's a bit more expressive.

If there are any valid reasons to keep empty as it is in RC2, feel free to close this issue :)

@alexandru

This comment has been minimized.

Copy link
Member

commented Nov 8, 2018

@sirmax will consider reverting it.

In the meantime you can also do: Cancelable.empty : Cancelable.
This is a type-checked upcast.

source.scan(Cancelable.empty : Cancelable) { ??? }
@sirmax

This comment has been minimized.

Copy link
Author

commented Nov 8, 2018

Cancelable.empty : Cancelable is too wordy to my taste, I'll keep using Cancelable() for now which is effectively Cancelable.empty.

@alexandru

This comment has been minimized.

Copy link
Member

commented Nov 8, 2018

Well, Cancelable.empty is empty, meaning it doesn't allocate anything, it's the same instance being reused over and over again.

@alexandru

This comment has been minimized.

Copy link
Member

commented Nov 8, 2018

I think you're right btw, this isn't a very nice change.

@sirmax

This comment has been minimized.

Copy link
Author

commented Nov 8, 2018

Well, Cancelable.empty is empty, meaning it doesn't allocate anything

But Cancelable() is the same

object Cancelable {
  /** Builds a [[monix.execution.Cancelable Cancelable]]. */
  def apply(): Cancelable =
    empty

Although yes, I know, one shouldn't rely on an implementation :)

@alexandru alexandru added this to the 3.0.0 milestone Nov 16, 2018

oleg-py added a commit to oleg-py/monix that referenced this issue Feb 2, 2019

@alexandru alexandru closed this in b960229 Feb 5, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.