Skip to content

Commit ecd3705

Browse files
author
jmhofer
committed
updated to Scala 2.10.2 again, repaired Scala tests, generalized two more zip methods
1 parent 1b32a19 commit ecd3705

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

language-adaptors/rxjava-scala/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ sourceSets {
2121
}
2222

2323
dependencies {
24-
// pinning to 2.10.1 as having issues with 2.10.2
25-
compile 'org.scala-lang:scala-library:2.10.1'
24+
compile 'org.scala-lang:scala-library:2.10.2'
2625

2726
compile project(':rxjava-core')
2827

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/RxImplicits.scala

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ object RxImplicits {
106106
* type never escapes the for-comprehension
107107
*/
108108
implicit class ScalaObservable[A](wrapped: Observable[A]) {
109-
def map[B](f: A => B): Observable[B] = wrapped.map(f)
109+
def map[B](f: A => B): Observable[B] = wrapped.map[B](f)
110110
def flatMap[B](f: A => Observable[B]): Observable[B] = wrapped.mapMany(f)
111111
def foreach(f: A => Unit): Unit = wrapped.toBlockingObservable.forEach(f)
112112
def withFilter(p: A => Boolean): WithFilter = new WithFilter(p)
@@ -147,7 +147,7 @@ class UnitTestSuite extends JUnitSuite {
147147
class ObservableWithException(s: Subscription, values: String*) extends Observable[String] {
148148
var t: Thread = null
149149

150-
override def subscribe(observer: Observer[String]): Subscription = {
150+
override def subscribe(observer: Observer[_ >: String]): Subscription = {
151151
println("ObservableWithException subscribed to ...")
152152
t = new Thread(new Runnable() {
153153
override def run() {
@@ -272,6 +272,18 @@ class UnitTestSuite extends JUnitSuite {
272272
assertSubscribeReceives(synchronized)(1, 2, 3)
273273
}
274274

275+
@Test def testZip2() {
276+
val colors: Observable[String] = Observable.from("red", "green", "blue")
277+
val names: Observable[String] = Observable.from("lion-o", "cheetara", "panthro")
278+
279+
case class Character(color: String, name: String)
280+
281+
val cheetara = Character("green", "cheetara")
282+
val panthro = Character("blue", "panthro")
283+
val characters = Observable.zip[Character, String, String](colors, names, Character.apply _)
284+
assertSubscribeReceives(characters)(cheetara, panthro)
285+
}
286+
275287
@Test def testZip3() {
276288
val numbers = Observable.from(1, 2, 3)
277289
val colors = Observable.from("red", "green", "blue")
@@ -283,7 +295,7 @@ class UnitTestSuite extends JUnitSuite {
283295
val cheetara = Character(2, "green", "cheetara")
284296
val panthro = Character(3, "blue", "panthro")
285297

286-
val characters = Observable.zip(numbers, colors, names, Character.apply _)
298+
val characters = Observable.zip[Character, Int, String, String](numbers, colors, names, Character.apply _)
287299
assertSubscribeReceives(characters)(liono, cheetara, panthro)
288300
}
289301

@@ -299,7 +311,7 @@ class UnitTestSuite extends JUnitSuite {
299311
val cheetara = Character(2, "green", "cheetara", false)
300312
val panthro = Character(3, "blue", "panthro", false)
301313

302-
val characters = Observable.zip(numbers, colors, names, isLeader, Character.apply _)
314+
val characters = Observable.zip[Character, Int, String, String, Boolean](numbers, colors, names, isLeader, Character.apply _)
303315
assertSubscribeReceives(characters)(liono, cheetara, panthro)
304316
}
305317

@@ -459,18 +471,9 @@ class UnitTestSuite extends JUnitSuite {
459471
assertSubscribeReceives(skipped)(3, 4)
460472
}
461473

462-
/**
463-
* Both testTake and testTakeWhileWithIndex exposed a bug with unsubscribes not properly propagating.
464-
* observable.take(2) produces onNext(first), onNext(second), and 4 onCompleteds
465-
* it should produce onNext(first), onNext(second), and 1 onCompleted
466-
*
467-
* Switching to Observable.create(OperationTake.take(observable, 2)) works as expected
468-
*/
469474
@Test def testTake {
470-
import rx.operators._
471-
472475
val observable = Observable.from(1, 2, 3, 4, 5)
473-
val took = Observable.create(OperationTake.take(observable, 2))
476+
val took = observable.take(2)
474477
assertSubscribeReceives(took)(1, 2)
475478
}
476479

@@ -480,11 +483,11 @@ class UnitTestSuite extends JUnitSuite {
480483
assertSubscribeReceives(took)(1, 3, 5)
481484
}
482485

483-
/*@Test def testTakeWhileWithIndex {
484-
val observable = Observable.from(1, 3, 5, 6, 7, 9, 11, 12, 13, 15, 17)
485-
val took = observable.takeWhileWithIndex((i: Int, idx: Int) => isOdd(i) && idx > 4)
486-
assertSubscribeReceives(took)(9, 11)
487-
}*/
486+
@Test def testTakeWhileWithIndex {
487+
val observable = Observable.from(1, 3, 5, 7, 9, 11, 12, 13, 15, 17)
488+
val took = observable.takeWhileWithIndex((i: Int, idx: Int) => isOdd(i) && idx < 8)
489+
assertSubscribeReceives(took)(1, 3, 5, 7, 9, 11)
490+
}
488491

489492
@Test def testTakeLast {
490493
val observable = Observable.from(1, 2, 3, 4, 5, 6, 7, 8, 9)

rxjava-core/src/main/java/rx/Observable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ public static <R, T0, T1, T2> Observable<R> zip(Observable<? extends T0> w0, Obs
10231023
* Observables, results in an item that will be emitted by the resulting Observable
10241024
* @return an Observable that emits the zipped results
10251025
*/
1026-
public static <R, T0, T1, T2, T3> Observable<R> zip(Observable<T0> w0, Observable<T1> w1, Observable<T2> w2, Observable<T3> w3, Func4<? super T0, ? super T1, ? super T2, ? super T3, ? extends R> reduceFunction) {
1026+
public static <R, T0, T1, T2, T3> Observable<R> zip(Observable<? extends T0> w0, Observable<? extends T1> w1, Observable<? extends T2> w2, Observable<? extends T3> w3, Func4<? super T0, ? super T1, ? super T2, ? super T3, ? extends R> reduceFunction) {
10271027
return create(OperationZip.zip(w0, w1, w2, w3, reduceFunction));
10281028
}
10291029

0 commit comments

Comments
 (0)