Skip to content

Commit baf568d

Browse files
committed
Add 'dropUntil' to RxScala
1 parent 29f564a commit baf568d

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

language-adaptors/rxjava-scala/src/examples/scala/rx/lang/scala/examples/RxScalaDemo.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,15 @@ class RxScalaDemo extends JUnitSuite {
426426
)
427427
}
428428

429+
@Test def dropUntilExample() {
430+
val o = List("Alice", "Bob", "Carlos").toObservable.zip(
431+
Observable.interval(700 millis, IOScheduler())).map(_._1) // emit every 700 millis
432+
val other = List(1).toObservable.delay(1 seconds)
433+
println(
434+
o.dropUntil(other).toBlockingObservable.toList // output List("Bob", "Carlos")
435+
)
436+
}
437+
429438
def square(x: Int): Int = {
430439
println(s"$x*$x is being calculated on thread ${Thread.currentThread().getId}")
431440
Thread.sleep(100) // calculating a square is heavy work :)

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,22 @@ trait Observable[+T]
13271327
toScalaObservable(asJavaObservable.skipLast(time.length, time.unit, scheduler))
13281328
}
13291329

1330+
/**
1331+
* Returns an Observable that skips items emitted by the source Observable until a second Observable emits an item.
1332+
* <p>
1333+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/skipUntil.png">
1334+
*
1335+
* @param other the second Observable that has to emit an item before the source Observable's elements begin
1336+
* to be mirrored by the resulting Observable
1337+
* @return an Observable that skips items from the source Observable until the second Observable emits an
1338+
* item, then emits the remaining items
1339+
* @see <a href="https://github.com/Netflix/RxJava/wiki/Filtering-Observables#wiki-skipuntil">RxJava Wiki: skipUntil()</a>
1340+
* @see <a href="http://msdn.microsoft.com/en-us/library/hh229358.aspx">MSDN: Observable.SkipUntil</a>
1341+
*/
1342+
def dropUntil[E](other: Observable[E]): Observable[T] = {
1343+
toScalaObservable[T](asJavaObservable.skipUntil(other))
1344+
}
1345+
13301346
/**
13311347
* Returns an Observable that emits only the first `num` items emitted by the source
13321348
* Observable.

language-adaptors/rxjava-scala/src/test/scala/rx/lang/scala/CompletenessTest.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class CompletenessTest extends JUnitSuite {
9898
"skip(Long, TimeUnit, Scheduler)" -> "drop(Duration, Scheduler)",
9999
"skipWhile(Func1[_ >: T, Boolean])" -> "dropWhile(T => Boolean)",
100100
"skipWhileWithIndex(Func2[_ >: T, Integer, Boolean])" -> unnecessary,
101+
"skipUntil(Observable[U])" -> "dropUntil(Observable[E])",
101102
"startWith(Iterable[T])" -> "[unnecessary because we can just use `++` instead]",
102103
"skipLast(Int)" -> "dropRight(Int)",
103104
"skipLast(Long, TimeUnit)" -> "dropRight(Duration)",

0 commit comments

Comments
 (0)