Skip to content

Commit

Permalink
Add flatMapIterable and concatMapIterable (ReactiveX#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
bemusementpark authored and stepango committed Jul 12, 2018
1 parent d20fa56 commit 545f913
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/kotlin/io/reactivex/rxkotlin/observable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ fun <T : Any> Iterable<Observable<out T>>.merge(): Observable<T> = Observable.me
@SchedulerSupport(SchedulerSupport.NONE)
fun <T : Any> Iterable<Observable<out T>>.mergeDelayError(): Observable<T> = Observable.mergeDelayError(this.toObservable())

fun <T : Any> Observable<out Iterable<T>>.flatMapIterable(): Observable<T> = flatMapIterable { it }
fun <T : Any> Observable<out Iterable<T>>.concatMapIterable(): Observable<T> = concatMapIterable { it }

/**
* Returns Observable that emits objects from kotlin [Sequence] returned by function you provided by parameter [body] for
* each input object and merges all produced elements into one observable.
Expand Down
14 changes: 14 additions & 0 deletions src/test/kotlin/io/reactivex/rxkotlin/ObservableTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ class ObservableTest {
)
}

@Test fun testFlatMapIterable() {
assertEquals(
listOf(1, 2, 3),
Observable.just(listOf(1, 2, 3)).flatMapIterable().toList().blockingGet()
)
}

@Test fun testConcatMapIterable() {
assertEquals(
listOf(1, 2, 3, 4),
Observable.just(listOf(1, 2, 3) , listOf(4)).concatMapIterable().toList().blockingGet()
)
}

@Test fun testCombineLatest() {
val list = listOf(1, 2, 3, 2, 3, 4, 3, 4, 5)
assertEquals(list, list.map { Observable.just(it) }.combineLatest { it }.blockingFirst())
Expand Down

0 comments on commit 545f913

Please sign in to comment.