@@ -1512,6 +1512,40 @@ trait Observable[+T]
1512
1512
toScalaObservable[R ](thisJava.publish(fJava, initialValue))
1513
1513
}
1514
1514
1515
+ /**
1516
+ * Returns a [[ConnectableObservable ]] that emits only the last item emitted by the source Observable.
1517
+ * A [[ConnectableObservable ]] resembles an ordinary Observable, except that it does not begin emitting items
1518
+ * when it is subscribed to, but only when its `connect` method is called.
1519
+ * <p>
1520
+ * <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/publishLast.png">
1521
+ *
1522
+ * @return a [[ConnectableObservable ]] that emits only the last item emitted by the source Observable
1523
+ */
1524
+ def publishLast : ConnectableObservable [T ] = {
1525
+ new ConnectableObservable [T ](asJavaObservable.publishLast())
1526
+ }
1527
+
1528
+ /**
1529
+ * Returns an Observable that emits an item that results from invoking a specified selector on the last item
1530
+ * emitted by a [[ConnectableObservable ]] that shares a single subscription to the source Observable.
1531
+ * <p>
1532
+ * <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/publishLast.f.png">
1533
+ *
1534
+ * @param selector a function that can use the multicasted source sequence as many times as needed, without
1535
+ * causing multiple subscriptions to the source Observable. Subscribers to the source will only
1536
+ * receive the last item emitted by the source.
1537
+ * @return an Observable that emits an item that is the result of invoking the selector on a [[ConnectableObservable ]]
1538
+ * that shares a single subscription to the source Observable
1539
+ */
1540
+ def publishLast [R ](selector : Observable [T ] => Observable [R ]): Observable [R ] = {
1541
+ val thisJava = this .asJavaObservable.asInstanceOf [rx.Observable [T ]]
1542
+ val fJava = new rx.functions.Func1 [rx.Observable [T ], rx.Observable [R ]]() {
1543
+ override def call (jo : rx.Observable [T ]): rx.Observable [R ] =
1544
+ selector(toScalaObservable[T ](jo)).asJavaObservable.asInstanceOf [rx.Observable [R ]]
1545
+ }
1546
+ toScalaObservable[R ](thisJava.publishLast(fJava))
1547
+ }
1548
+
1515
1549
// TODO add Scala-like aggregate function
1516
1550
1517
1551
/**
0 commit comments