@@ -1145,10 +1145,64 @@ trait Observable[+T]
1145
1145
*
1146
1146
* @return an [[rx.lang.scala.observables.ConnectableObservable ]].
1147
1147
*/
1148
- def publish : ConnectableObservable [T ] = {
1148
+ def publish () : ConnectableObservable [T ] = {
1149
1149
new ConnectableObservable [T ](asJavaObservable.publish())
1150
1150
}
1151
1151
1152
+
1153
+ /**
1154
+ * Returns an Observable that emits `initialValue` followed by the items emitted by a `ConnectableObservable` that shares a single subscription to the source Observable.
1155
+ * <p>
1156
+ * <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/publishConnect.i.png">
1157
+ *
1158
+ * @param initialValue the initial value to be emitted by the resulting Observable
1159
+ * @return a `ConnectableObservable` that shares a single subscription to the underlying Observable and starts with `initialValue`
1160
+ */
1161
+ def publish [U >: T ](initialValue : U ): ConnectableObservable [U ] = {
1162
+ val thisJava = this .asJavaObservable.asInstanceOf [rx.Observable [U ]]
1163
+ new ConnectableObservable [U ](thisJava.publish(initialValue))
1164
+ }
1165
+
1166
+ /**
1167
+ * Returns an Observable that emits the results of invoking a specified selector on items emitted by a `ConnectableObservable`
1168
+ * that shares a single subscription to the underlying sequence.
1169
+ * <p>
1170
+ * <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/publishConnect.f.png">
1171
+ *
1172
+ * @param selector a function that can use the multicasted source sequence as many times as needed, without
1173
+ * causing multiple subscriptions to the source sequence. Subscribers to the given source will
1174
+ * receive all notifications of the source from the time of the subscription forward.
1175
+ * @return an Observable that emits the results of invoking the selector on the items emitted by a `ConnectableObservable`
1176
+ * that shares a single subscription to the underlying sequence
1177
+ */
1178
+ def publish [U >: T , R ](selector : Observable [U ] => Observable [R ]): Observable [R ] = {
1179
+ val thisJava = this .asJavaObservable.asInstanceOf [rx.Observable [U ]]
1180
+ val fJava : Func1 [rx.Observable [U ], rx.Observable [R ]] =
1181
+ (jo : rx.Observable [U ]) => selector(toScalaObservable[U ](jo)).asJavaObservable.asInstanceOf [rx.Observable [R ]]
1182
+ toScalaObservable[R ](thisJava.publish(fJava))
1183
+ }
1184
+
1185
+ /**
1186
+ * Returns an Observable that emits `initialValue` followed by the results of invoking a specified
1187
+ * selector on items emitted by a `ConnectableObservable` that shares a single subscription to the
1188
+ * source Observable.
1189
+ * <p>
1190
+ * <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/publishConnect.if.png">
1191
+ *
1192
+ * @param selector a function that can use the multicasted source sequence as many times as needed, without
1193
+ * causing multiple subscriptions to the source Observable. Subscribers to the source will
1194
+ * receive all notifications of the source from the time of the subscription forward
1195
+ * @param initialValue the initial value of the underlying `BehaviorSubject`
1196
+ * @return an Observable that emits `initialValue` followed by the results of invoking the selector
1197
+ * on a `ConnectableObservable` that shares a single subscription to the underlying Observable
1198
+ */
1199
+ def publish [U >: T , R ](selector : Observable [U ] => Observable [R ], initialValue : U ): Observable [R ] = {
1200
+ val thisJava = this .asJavaObservable.asInstanceOf [rx.Observable [U ]]
1201
+ val fJava : Func1 [rx.Observable [U ], rx.Observable [R ]] =
1202
+ (jo : rx.Observable [U ]) => selector(toScalaObservable[U ](jo)).asJavaObservable.asInstanceOf [rx.Observable [R ]]
1203
+ toScalaObservable[R ](thisJava.publish(fJava, initialValue))
1204
+ }
1205
+
1152
1206
// TODO add Scala-like aggregate function
1153
1207
1154
1208
/**
0 commit comments