Skip to content

Commit

Permalink
Removes overload of map operators for better type inference
Browse files Browse the repository at this point in the history
  • Loading branch information
LukaJCB committed Dec 13, 2016
1 parent fa1ab9d commit 924aa2e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 53 deletions.
49 changes: 2 additions & 47 deletions src/main/scala/rxscalajs/Observable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -810,22 +810,6 @@ class Observable[+T] protected[rxscalajs](val inner: ObservableFacade[T]) {
new Observable(inner.asInstanceOf[ObservableFacade[Observable[U]]].map((n: Observable[U]) => n.get).concatAll())
}

/**
* Returns a new Observable that emits items resulting from applying a function that you supply to each item
* emitted by the source Observable, where that function returns an Observable, and then emitting the items
* that result from concatinating those resulting Observables.
*
* <img width="640" height="305" src="https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/concatMap.png" alt="" />
*
* @param project a function that, when applied to an item emitted by the source Observable, returns an Observable
*
* @return an Observable that emits the result of applying the transformation function to each item emitted
* by the source Observable and concatinating the Observables obtained from this transformation
*/
def concatMap[R](project: (T, Int) => Observable[R]): Observable[R] = {
new Observable(inner.concatMap(toReturnFacade(project)))
}

/**
* Returns a new Observable that emits items resulting from applying a function that you supply to each item
* emitted by the source Observable, where that function returns an Observable, and then emitting the items
Expand Down Expand Up @@ -1589,22 +1573,7 @@ class Observable[+T] protected[rxscalajs](val inner: ObservableFacade[T]) {
mergeAll()
}

/**
* Returns an [[Observable]] that emits items based on applying a function that you supply to each item emitted
* by the source [[Observable]] , where that function returns an [[Observable]] , and then merging those resulting
* [[Observable]]s and emitting the results of this merger, while limiting the maximum number of concurrent
* subscriptions to these [[Observable]]s.
*
* <img width="640" height="380" src="http://reactivex.io/documentation/operators/images/flatMap.c.png" alt="" />
*
* @param project a function that, when applied to an item emitted by the source [[Observable]], returns an [[Observable]]
*
* @return an [[Observable]] that emits the result of applying the transformation function to each item emitted
* by the source [[Observable]] and merging the results of the [[Observable]]s obtained from this transformation
*/
def mergeMap[R](project: (T, Int) => Observable[R]): Observable[R] = {
new Observable(inner.mergeMap[R](toReturnFacade(project)))
}

/**
* Returns an [[Observable]] that emits items based on applying a function that you supply to each item emitted
* by the source [[Observable]] , where that function returns an [[Observable]] , and then merging those resulting
Expand Down Expand Up @@ -2153,21 +2122,7 @@ class Observable[+T] protected[rxscalajs](val inner: ObservableFacade[T]) {
new Observable[U](inner.asInstanceOf[ObservableFacade[Observable[U]]].map((n: Observable[U]) => n.get).switch())
}

/**
* Returns a new Observable by applying a function that you supply to each item emitted by the source
* Observable that returns an Observable, and then emitting the items emitted by the most recently emitted
* of these Observables.
*
* <img width="640" height="350" src="https://raw.githubusercontent.com/wiki/ReactiveX/RxJava/images/rx-operators/switchMap.png" alt="" />
*
* @param project a function that, when applied to an item emitted by the source Observable, returns an Observable
*
* @return an Observable that emits the items emitted by the Observable returned from applying a function to
* the most recently emitted item emitted by the source Observable
*/
def switchMap[R](project: (T, Int) => Observable[R]): Observable[R] = {
new Observable(inner.switchMap(toReturnFacade(project)))
}

/**
* Returns a new Observable by applying a function that you supply to each item emitted by the source
* Observable that returns an Observable, and then emitting the items emitted by the most recently emitted
Expand Down
12 changes: 6 additions & 6 deletions src/test/scala/rxscalajs/ObservableTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,12 @@ object ObservableTest extends TestSuite {
'CombineLatest {
val xs = Vector(1,2,3,4).map(x => Observable.just(x))
val obs = Observable.combineLatest(xs)
obs(println)
obs(unit)
}
'CombineLatestWith {
val xs = List(1,2,3,4).map(x => Observable.just(x))
val obs = Observable.combineLatestWith(xs)(_.sum)
obs(println)
obs(unit)
}
}
'WrapperTests{
Expand Down Expand Up @@ -332,8 +332,8 @@ object ObservableTest extends TestSuite {
hoObs.concatAll.subscribe(unit)
}
'ConcatMap {
obs.concatMap((n: Int, index: Int) => Observable.range(0, n)).subscribe(unit)
obs.concatMap[String]((n: Int, index: Int) => Observable.of("Hello", "world")).subscribe(unit)
obs.concatMap(n=> Observable.range(0, n)).subscribe(unit)
obs.concatMap[String](n=> Observable.of("Hello", "world")).subscribe(unit)
}
'ConcatMapTo {
obs.concatMapTo(Observable.just('H')).subscribe(unit)
Expand Down Expand Up @@ -429,7 +429,7 @@ object ObservableTest extends TestSuite {
hoObs.mergeAll(3).subscribe(unit)
}
'MergeMap {
obs.mergeMap((n: Int, index: Int) => Observable.of(n)).subscribe(unit)
obs.mergeMap((n: Int) => Observable.of(n)).subscribe(unit)
obs.mergeMap(n => Observable.just(n)).subscribe(unit)
}
'MergeMapTo {
Expand Down Expand Up @@ -501,7 +501,7 @@ object ObservableTest extends TestSuite {
hoObs.switch.subscribe(unit)
}
'SwitchMap {
val func = (n: Observable[Int], n2: Int) => Observable.of(n2)
val func = (n: Observable[Int]) => Observable.of(n)
hoObs.switchMap(func).subscribe(unit)
}
'SwitchMapTo {
Expand Down

0 comments on commit 924aa2e

Please sign in to comment.