Skip to content

Commit a1f7c02

Browse files
Observable.sample(Observable) in Scala
1 parent 27c0956 commit a1f7c02

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,21 @@ trait Observable[+T]
11321132
toScalaObservable[T](asJavaObservable.sample(duration.length, duration.unit, scheduler))
11331133
}
11341134

1135+
/**
1136+
* Return an Observable that emits the results of sampling the items emitted by the source Observable
1137+
* whenever the specified sampler Observable emits an item or completes.
1138+
*
1139+
* <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/sample.o.png">
1140+
*
1141+
* @param sampler
1142+
* the Observable to use for sampling the source Observable
1143+
* @return an Observable that emits the results of sampling the items emitted by this Observable whenever
1144+
* the sampler Observable emits an item or completes
1145+
*/
1146+
def sample(sampler: Observable[Any]): Observable[T] = {
1147+
toScalaObservable[T](asJavaObservable.sample(sampler))
1148+
}
1149+
11351150
/**
11361151
* Returns an Observable that applies a function of your choosing to the first item emitted by a
11371152
* source Observable, then feeds the result of that function along with the second item emitted

0 commit comments

Comments
 (0)