@@ -2193,6 +2193,35 @@ trait Observable[+T]
2193
2193
toScalaObservable[(K , Observable [T ])](o1.map[(K , Observable [T ])](func))
2194
2194
}
2195
2195
2196
+ /**
2197
+ * Groups the items emitted by an [[Observable ]] (transformed by a selector) according to a specified key selector function
2198
+ * until the duration Observable expires for the key.
2199
+ *
2200
+ * <img width="640" height="375" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/groupByUntil.png">
2201
+ *
2202
+ * <em>Note:</em> The `Observable` in the pair `(K, Observable[V])` will cache the items it is to emit until such time as it
2203
+ * is subscribed to. For this reason, in order to avoid memory leaks, you should not simply ignore those `Observable` that
2204
+ * do not concern you. Instead, you can signal to them that they may discard their buffers by applying an operator like `take(0)` to them.
2205
+ *
2206
+ * @param keySelector a function to extract the key for each item
2207
+ * @param valueSelector a function to map each item emitted by the source [[Observable ]] to an item emitted by one
2208
+ * of the resulting `Observable[V]`s
2209
+ * @param closings a function to signal the expiration of a group
2210
+ * @return an [[Observable ]] that emits pairs of key and `Observable[V]`, each of which corresponds to a key
2211
+ * value and each of which emits all items emitted by the source [[Observable ]] during that
2212
+ * key's duration that share that same key value, transformed by the value selector
2213
+ */
2214
+ def groupByUntil [K , V ](keySelector : T => K , valueSelector : T => V , closings : (K , Observable [V ]) => Observable [Any ]): Observable [(K , Observable [V ])] = {
2215
+ val jKeySelector : Func1 [_ >: T , _ <: K ] = keySelector
2216
+ val jValueSelector : Func1 [_ >: T , _ <: V ] = valueSelector
2217
+ val jDurationSelector = new Func1 [rx.observables.GroupedObservable [_ <: K , _ <: V ], rx.Observable [_ <: Any ]] {
2218
+ override def call (jgo : rx.observables.GroupedObservable [_ <: K , _ <: V ]): rx.Observable [_ <: Any ] = closings(jgo.getKey, toScalaObservable[V ](jgo))
2219
+ }
2220
+ val f = (o : rx.observables.GroupedObservable [K , _ <: V ]) => (o.getKey, toScalaObservable[V ](o))
2221
+ val jo = asJavaObservable.groupByUntil[K , V , Any ](jKeySelector, jValueSelector, jDurationSelector).map[(K , Observable [V ])](f)
2222
+ toScalaObservable[(K , Observable [V ])](jo)
2223
+ }
2224
+
2196
2225
/**
2197
2226
* Correlates the items emitted by two Observables based on overlapping durations.
2198
2227
* <p>
0 commit comments