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

Scala Publish #640

Closed
headinthebox opened this issue Dec 19, 2013 · 3 comments
Closed

Scala Publish #640

headinthebox opened this issue Dec 19, 2013 · 3 comments
Assignees

Comments

@headinthebox
Copy link
Contributor

The current Scala bindings for publish are as follows:

def publish: (() => Subscription, Observable[T]) = {
val javaCO = asJavaObservable.publish()
(() => javaCO.connect(), toScalaObservableT)
}

This has a couple of downsides

  • It forces every caller has to invent names for the two pieces, whereas they already have names given by the callee.

    val (foo, bar) = baz.publish()

vs

val bar = baz.publish()
bar.subscribe(..)
bar.connect

  • It hides the fact that publish returns a connectable observable, so you cannot call refcount.
  • Why split up a nice object into a tuple of unrelated things. Maybe that makes sense if you want to pass the two pieces around separately, but that is typically not the case of connectable observables.

If I don't hear anyone screaming loudly, I am going to change this to mimic the Java signature.

@samuelgruetter
Copy link
Contributor

When I came up with this (() => Subscription, Observable) pattern, the Scala Observable extended AnyVal, so it was final and I could not make a ConnectableObservable extending it. But now this problem is gone, so I think it makes sense to replace (() => Subscription, Observable) by ConnectableObservable (of course, not only in publish, but also in multicast and replay).

There's a similar situation with groupBy: In Java, we have a GroupedObservable<K, T>, and in Scala we have a Observable[(K, Observable[T])]. Here, however, I wouldn't change anything, because an Observable emitting tuples which map keys to Observables makes more sense than claiming that the key is part of the Observable, and also, the tuples allow nice for comprehensions like for ((key, obs) <- o.groupBy(...)).

@ghost ghost assigned headinthebox Jan 2, 2014
@benjchristensen
Copy link
Member

@headinthebox @samuelgruetter Has this been resolved?

@zsxwing
Copy link
Member

zsxwing commented May 20, 2014

Should be resolved in #1160

jihoonson pushed a commit to jihoonson/RxJava that referenced this issue Mar 6, 2020
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

No branches or pull requests

4 participants