Skip to content

Commit 02e6903

Browse files
committed
Merge pull request #3718 from ginbalin/1.x
new method concatMapIterable #3713
2 parents a57bccc + 2440001 commit 02e6903

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/main/java/rx/Observable.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3889,6 +3889,29 @@ public final <R> Observable<R> concatMap(Func1<? super T, ? extends Observable<?
38893889
return concat(map(func));
38903890
}
38913891

3892+
/**
3893+
* Returns an Observable that concatenate each item emitted by the source Observable with the values in an
3894+
* Iterable corresponding to that item that is generated by a selector.
3895+
* <p>
3896+
*
3897+
* <dl>
3898+
* <dt><b>Scheduler:</b></dt>
3899+
* <dd>{@code concatMapIterable} does not operate by default on a particular {@link Scheduler}.</dd>
3900+
* </dl>
3901+
*
3902+
* @param <R>
3903+
* the type of item emitted by the resulting Observable
3904+
* @param collectionSelector
3905+
* a function that returns an Iterable sequence of values for when given an item emitted by the
3906+
* source Observable
3907+
* @return an Observable that emits the results of concatenating the items emitted by the source Observable with
3908+
* the values in the Iterables corresponding to those items, as generated by {@code collectionSelector}
3909+
* @see <a href="http://reactivex.io/documentation/operators/flatmap.html">ReactiveX operators documentation: FlatMap</a>
3910+
*/
3911+
public final <R> Observable<R> concatMapIterable(Func1<? super T, ? extends Iterable<? extends R>> collectionSelector) {
3912+
return concat(map(OperatorMapPair.convertSelector(collectionSelector)));
3913+
}
3914+
38923915
/**
38933916
* Returns an Observable that emits the items emitted from the current Observable, then the next, one after
38943917
* the other, without interleaving them.

src/test/java/rx/internal/operators/OperatorConcatTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,34 @@ public void testConcatWithList() {
8282

8383
verify(observer, times(7)).onNext(anyString());
8484
}
85+
86+
@Test
87+
public void testConcatMapIterable() {
88+
@SuppressWarnings("unchecked")
89+
Observer<String> observer = mock(Observer.class);
90+
91+
final String[] l = { "a", "b", "c", "d", "e" };
92+
93+
Func1<List<String>,List<String>> identity = new Func1<List<String>, List<String>>() {
94+
@Override
95+
public List<String> call(List<String> t) {
96+
return t;
97+
}
98+
};
99+
100+
final Observable<List<String>> listObs = Observable.just(Arrays.asList(l));
101+
final Observable<String> concatMap = listObs.concatMapIterable(identity);
102+
103+
concatMap.subscribe(observer);
104+
105+
InOrder inOrder = inOrder(observer);
106+
inOrder.verify(observer, times(1)).onNext("a");
107+
inOrder.verify(observer, times(1)).onNext("b");
108+
inOrder.verify(observer, times(1)).onNext("c");
109+
inOrder.verify(observer, times(1)).onNext("d");
110+
inOrder.verify(observer, times(1)).onNext("e");
111+
inOrder.verify(observer, times(1)).onCompleted();
112+
}
85113

86114
@Test
87115
public void testConcatObservableOfObservables() {

0 commit comments

Comments
 (0)