Skip to content

Commit 69e5ffd

Browse files
committed
add examples of toMap to RxScalaDemo
Added examples for all three overloads and removed newlines between methods and docs
1 parent 31cfd19 commit 69e5ffd

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

language-adaptors/rxjava-scala/src/examples/scala/rx/lang/scala/examples/RxScalaDemo.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,4 +573,28 @@ class RxScalaDemo extends JUnitSuite {
573573
val o : Observable[Seq[Char]] = List("red".toList, "green".toList, "blue".toList).toObservable.elementAtOrDefault(3, "black".toSeq)
574574
println(o.toBlockingObservable.single)
575575
}
576+
577+
@Test def toMapExample1(): Unit = {
578+
val o : Observable[String] = List("alice", "bob", "carol").toObservable
579+
val keySelector = (s: String) => s.head
580+
val m = o.toMap(keySelector)
581+
println(m.toBlockingObservable.single)
582+
}
583+
584+
@Test def toMapExample2(): Unit = {
585+
val o : Observable[String] = List("alice", "bob", "carol").toObservable
586+
val keySelector = (s: String) => s.head
587+
val valueSelector = (s: String) => s.tail
588+
val m = o.toMap(keySelector, valueSelector)
589+
println(m.toBlockingObservable.single)
590+
}
591+
592+
@Test def toMapExample3(): Unit = {
593+
val o : Observable[String] = List("alice", "bob", "carol").toObservable
594+
val keySelector = (s: String) => s.head
595+
val valueSelector = (s: String) => s.tail
596+
val mapFactory = () => Map('s'->"tart")
597+
val m = o.toMap(keySelector, valueSelector, mapFactory)
598+
println(m.toBlockingObservable.single)
599+
}
576600
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2378,7 +2378,6 @@ trait Observable[+T]
23782378
* @return an Observable that emits a single item: a Map containing the mapped items from the source
23792379
* Observable
23802380
*/
2381-
23822381
def toMap[K] (keySelector: T => K): Observable[Map[K, T]]= {
23832382
toScalaObservable[Map[K,T]](asJavaObservable.toMap(keySelector))
23842383
}
@@ -2399,7 +2398,6 @@ trait Observable[+T]
23992398
* @return an Observable that emits a single item: a HashMap containing the mapped items from the source
24002399
* Observable
24012400
*/
2402-
24032401
def toMap[K, V] (keySelector: T => K, valueSelector: T => V) : Observable[Map[K, V]] = {
24042402
toScalaObservable[Map[K,V]](asJavaObservable.toMap(keySelector, valueSelector))
24052403
}
@@ -2419,7 +2417,7 @@ trait Observable[+T]
24192417
* @return an Observable that emits a single item: a Map that contains the mapped items emitted by the
24202418
* source Observable
24212419
*/
2422-
def toMap[K, V] (keySelector: T => K, valueSelector: T => V, mapFactory: () => Observable[Map[K,V]]): Observable[Map[K,V]] = {
2420+
def toMap[K, V] (keySelector: T => K, valueSelector: T => V, mapFactory: () => Map[K,V]): Observable[Map[K,V]] = {
24232421
toScalaObservable[Map[K,V]](asJavaObservable.toMap(keySelector, valueSelector, mapFactory))
24242422
}
24252423

0 commit comments

Comments
 (0)