@@ -3880,6 +3880,83 @@ trait Observable[+T]
3880
3880
def longCount : Observable [Long ] = {
3881
3881
toScalaObservable[java.lang.Long ](asJavaObservable.longCount()).map(_.longValue())
3882
3882
}
3883
+
3884
+ /**
3885
+ * Returns an Observable that emits a single `Map` that contains an `Seq` of items emitted by the
3886
+ * source Observable keyed by a specified keySelector` function.
3887
+ *
3888
+ * <img width="640" height="305" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/toMultiMap.png">
3889
+ *
3890
+ * @param keySelector the function that extracts the key from the source items to be used as key in the HashMap
3891
+ * @return an Observable that emits a single item: a `Map` that contains an `Seq` of items mapped from
3892
+ * the source Observable
3893
+ */
3894
+ def toMultimap [K ](keySelector : T => K ): Observable [Map [K , Seq [T ]]] = {
3895
+ val thisJava = asJavaObservable.asInstanceOf [rx.Observable [T ]]
3896
+ val o : rx.Observable [java.util.Map [K , java.util.Collection [T ]]] = thisJava.toMultimap[K ](keySelector)
3897
+ toScalaObservable[java.util.Map [K , java.util.Collection [T ]]](o).map(m => m.toMap.mapValues(_.toSeq))
3898
+ }
3899
+
3900
+ /**
3901
+ * Returns an Observable that emits a single `Map` that contains an `Seq` of values extracted by a
3902
+ * specified `valueSelector` function from items emitted by the source Observable, keyed by a
3903
+ * specified `keySelector` function.
3904
+ *
3905
+ * <img width="640" height="305" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/toMultiMap.png">
3906
+ *
3907
+ * @param keySelector the function that extracts a key from the source items to be used as key in the HashMap
3908
+ * @param valueSelector the function that extracts a value from the source items to be used as value in the HashMap
3909
+ * @return an Observable that emits a single item: a `Map` that contains an `Seq` of items mapped from
3910
+ * the source Observable
3911
+ */
3912
+ def toMultimap [K , V ](keySelector : T => K , valueSelector : T => V ): Observable [Map [K , Seq [V ]]] = {
3913
+ val thisJava = asJavaObservable.asInstanceOf [rx.Observable [T ]]
3914
+ val o : rx.Observable [java.util.Map [K , java.util.Collection [V ]]] = thisJava.toMultimap[K , V ](keySelector, valueSelector)
3915
+ toScalaObservable[java.util.Map [K , java.util.Collection [V ]]](o).map(m => m.toMap.mapValues(_.toSeq))
3916
+ }
3917
+
3918
+ /**
3919
+ * Returns an Observable that emits a single `Map`, returned by a specified mapFactory` function, that
3920
+ * contains an `Seq` of values, extracted by a specified `valueSelector` function from items
3921
+ * emitted by the source Observable and keyed by the `keySelector` function.
3922
+ *
3923
+ * <img width="640" height="305" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/toMultiMap.png">
3924
+ *
3925
+ * @param keySelector the function that extracts a key from the source items to be used as the key in the Map
3926
+ * @param valueSelector the function that extracts a value from the source items to be used as the value in the Map
3927
+ * @param mapFactory he function that returns a Map instance to be used
3928
+ * @return an Observable that emits a single item: a `Map` that contains a `Seq` items mapped from the source
3929
+ * Observable
3930
+ */
3931
+ def toMultimap [K , V ](keySelector : T => K , valueSelector : T => V , mapFactory : () => Map [K , Seq [V ]]): Observable [Map [K , Seq [V ]]] = {
3932
+ val thisJava = asJavaObservable.asInstanceOf [rx.Observable [T ]]
3933
+ val o : rx.Observable [java.util.Map [K , java.util.Collection [V ]]] = thisJava.toMultimap[K , V ](keySelector, valueSelector)
3934
+ toScalaObservable[java.util.Map [K , java.util.Collection [V ]]](o).map(m => mapFactory() ++ m.toMap.mapValues(_.toSeq))
3935
+ }
3936
+
3937
+ /**
3938
+ * Returns an Observable that emits a single `Map`, returned by a specified `mapFactory` function, that
3939
+ * contains a custom `Seq` of values, extracted by a specified `valueSelector` function from
3940
+ * items emitted by the source Observable, and keyed by the `keySelector` function.
3941
+ *
3942
+ * <img width="640" height="305" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/toMultiMap.png">
3943
+ *
3944
+ * @param keySelector the function that extracts a key from the source items to be used as the key in the Map
3945
+ * @param valueSelector the function that extracts a value from the source items to be used as the value in the Map
3946
+ * @param mapFactory the function that returns a Map instance to be used
3947
+ * @param collectionFactory the function that returns a Collection instance for a particular key to be used in the Map
3948
+ * @return an Observable that emits a single item: a `Map` that contains the `Seq` of mapped items from
3949
+ * the source Observable
3950
+ */
3951
+ def toMultimap [K , V ](keySelector : T => K , valueSelector : T => V , mapFactory : () => Map [K , Seq [V ]], collectionFactory : K => Seq [V ]): Observable [Map [K , Seq [V ]]] = {
3952
+ val thisJava = asJavaObservable.asInstanceOf [rx.Observable [T ]]
3953
+ val o : rx.Observable [java.util.Map [K , java.util.Collection [V ]]] = thisJava.toMultimap[K , V ](keySelector, valueSelector)
3954
+ toScalaObservable[java.util.Map [K , java.util.Collection [V ]]](o).map {
3955
+ m => mapFactory() ++ m.toMap.map {
3956
+ case (k : K , v : java.util.Collection [V ]) => (k, collectionFactory(k) ++ v)
3957
+ }
3958
+ }
3959
+ }
3883
3960
}
3884
3961
3885
3962
/**
0 commit comments