Skip to content

Commit 0f73283

Browse files
authored
2.x: Add finite requirement to various collector operators JavaDoc (#5856)
* 2.x: Add finite requirement to various collector operators * Updated wording to "accumulator object"
1 parent 7ede8ee commit 0f73283

File tree

2 files changed

+158
-33
lines changed

2 files changed

+158
-33
lines changed

src/main/java/io/reactivex/Flowable.java

Lines changed: 80 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6706,12 +6706,16 @@ public final <U> Flowable<U> cast(final Class<U> clazz) {
67066706
}
67076707

67086708
/**
6709-
* Collects items emitted by the source Publisher into a single mutable data structure and returns
6709+
* Collects items emitted by the finite source Publisher into a single mutable data structure and returns
67106710
* a Single that emits this structure.
67116711
* <p>
67126712
* <img width="640" height="330" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/collect.png" alt="">
67136713
* <p>
67146714
* This is a simplified version of {@code reduce} that does not need to return the state on each pass.
6715+
* <p>
6716+
* Note that this operator requires the upstream to signal {@code onComplete} for the accumulator object to
6717+
* be emitted. Sources that are infinite and never complete will never emit anything through this
6718+
* operator and an infinite source may lead to a fatal {@code OutOfMemoryError}.
67156719
* <dl>
67166720
* <dt><b>Backpressure:</b></dt>
67176721
* <dd>This operator does not support backpressure because by intent it will receive all values and reduce
@@ -6740,12 +6744,16 @@ public final <U> Single<U> collect(Callable<? extends U> initialItemSupplier, Bi
67406744
}
67416745

67426746
/**
6743-
* Collects items emitted by the source Publisher into a single mutable data structure and returns
6747+
* Collects items emitted by the finite source Publisher into a single mutable data structure and returns
67446748
* a Single that emits this structure.
67456749
* <p>
67466750
* <img width="640" height="330" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/collect.png" alt="">
67476751
* <p>
67486752
* This is a simplified version of {@code reduce} that does not need to return the state on each pass.
6753+
* <p>
6754+
* Note that this operator requires the upstream to signal {@code onComplete} for the accumulator object to
6755+
* be emitted. Sources that are infinite and never complete will never emit anything through this
6756+
* operator and an infinite source may lead to a fatal {@code OutOfMemoryError}.
67496757
* <dl>
67506758
* <dt><b>Backpressure:</b></dt>
67516759
* <dd>This operator does not support backpressure because by intent it will receive all values and reduce
@@ -11148,7 +11156,7 @@ public final Flowable<T> rebatchRequests(int n) {
1114811156
/**
1114911157
* Returns a Maybe that applies a specified accumulator function to the first item emitted by a source
1115011158
* Publisher, then feeds the result of that function along with the second item emitted by the source
11151-
* Publisher into the same function, and so on until all items have been emitted by the source Publisher,
11159+
* Publisher into the same function, and so on until all items have been emitted by the finite source Publisher,
1115211160
* and emits the final result from the final call to your function as its sole item.
1115311161
* <p>
1115411162
* If the source is empty, a {@code NoSuchElementException} is signalled.
@@ -11158,6 +11166,10 @@ public final Flowable<T> rebatchRequests(int n) {
1115811166
* This technique, which is called "reduce" here, is sometimes called "aggregate," "fold," "accumulate,"
1115911167
* "compress," or "inject" in other programming contexts. Groovy, for instance, has an {@code inject} method
1116011168
* that does a similar operation on lists.
11169+
* <p>
11170+
* Note that this operator requires the upstream to signal {@code onComplete} for the accumulator object to
11171+
* be emitted. Sources that are infinite and never complete will never emit anything through this
11172+
* operator and an infinite source may lead to a fatal {@code OutOfMemoryError}.
1116111173
* <dl>
1116211174
* <dt><b>Backpressure:</b></dt>
1116311175
* <dd>The operator honors backpressure of its downstream consumer and consumes the
@@ -11186,7 +11198,7 @@ public final Maybe<T> reduce(BiFunction<T, T, T> reducer) {
1118611198
* Returns a Single that applies a specified accumulator function to the first item emitted by a source
1118711199
* Publisher and a specified seed value, then feeds the result of that function along with the second item
1118811200
* emitted by a Publisher into the same function, and so on until all items have been emitted by the
11189-
* source Publisher, emitting the final result from the final call to your function as its sole item.
11201+
* finite source Publisher, emitting the final result from the final call to your function as its sole item.
1119011202
* <p>
1119111203
* <img width="640" height="325" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/reduceSeed.png" alt="">
1119211204
* <p>
@@ -11211,6 +11223,10 @@ public final Maybe<T> reduce(BiFunction<T, T, T> reducer) {
1121111223
*
1121211224
* source.reduceWith(() -&gt; new ArrayList&lt;&gt;(), (list, item) -&gt; list.add(item)));
1121311225
* </code></pre>
11226+
* <p>
11227+
* Note that this operator requires the upstream to signal {@code onComplete} for the accumulator object to
11228+
* be emitted. Sources that are infinite and never complete will never emit anything through this
11229+
* operator and an infinite source may lead to a fatal {@code OutOfMemoryError}.
1121411230
* <dl>
1121511231
* <dt><b>Backpressure:</b></dt>
1121611232
* <dd>The operator honors backpressure of its downstream consumer and consumes the
@@ -11244,14 +11260,18 @@ public final <R> Single<R> reduce(R seed, BiFunction<R, ? super T, R> reducer) {
1124411260
* Returns a Single that applies a specified accumulator function to the first item emitted by a source
1124511261
* Publisher and a seed value derived from calling a specified seedSupplier, then feeds the result
1124611262
* of that function along with the second item emitted by a Publisher into the same function, and so on until
11247-
* all items have been emitted by the source Publisher, emitting the final result from the final call to your
11263+
* all items have been emitted by the finite source Publisher, emitting the final result from the final call to your
1124811264
* function as its sole item.
1124911265
* <p>
1125011266
* <img width="640" height="325" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/reduceSeed.png" alt="">
1125111267
* <p>
1125211268
* This technique, which is called "reduce" here, is sometimes called "aggregate," "fold," "accumulate,"
1125311269
* "compress," or "inject" in other programming contexts. Groovy, for instance, has an {@code inject} method
1125411270
* that does a similar operation on lists.
11271+
* <p>
11272+
* Note that this operator requires the upstream to signal {@code onComplete} for the accumulator object to
11273+
* be emitted. Sources that are infinite and never complete will never emit anything through this
11274+
* operator and an infinite source may lead to a fatal {@code OutOfMemoryError}.
1125511275
* <dl>
1125611276
* <dt><b>Backpressure:</b></dt>
1125711277
* <dd>The operator honors backpressure of its downstream consumer and consumes the
@@ -15175,12 +15195,16 @@ public final <U extends Collection<? super T>> Single<U> toList(Callable<U> coll
1517515195
}
1517615196

1517715197
/**
15178-
* Returns a Single that emits a single HashMap containing all items emitted by the source Publisher,
15198+
* Returns a Single that emits a single HashMap containing all items emitted by the finite source Publisher,
1517915199
* mapped by the keys returned by a specified {@code keySelector} function.
1518015200
* <p>
1518115201
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/toMap.png" alt="">
1518215202
* <p>
1518315203
* If more than one source item maps to the same key, the HashMap will contain the latest of those items.
15204+
* <p>
15205+
* Note that this operator requires the upstream to signal {@code onComplete} for the accumulated map to
15206+
* be emitted. Sources that are infinite and never complete will never emit anything through this
15207+
* operator and an infinite source may lead to a fatal {@code OutOfMemoryError}.
1518415208
* <dl>
1518515209
* <dt><b>Backpressure:</b></dt>
1518615210
* <dd>The operator honors backpressure from downstream and consumes the source {@code Publisher} in an
@@ -15206,12 +15230,16 @@ public final <K> Single<Map<K, T>> toMap(final Function<? super T, ? extends K>
1520615230

1520715231
/**
1520815232
* Returns a Single that emits a single HashMap containing values corresponding to items emitted by the
15209-
* source Publisher, mapped by the keys returned by a specified {@code keySelector} function.
15233+
* finite source Publisher, mapped by the keys returned by a specified {@code keySelector} function.
1521015234
* <p>
1521115235
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/toMap.png" alt="">
1521215236
* <p>
1521315237
* If more than one source item maps to the same key, the HashMap will contain a single entry that
1521415238
* corresponds to the latest of those items.
15239+
* <p>
15240+
* Note that this operator requires the upstream to signal {@code onComplete} for the accumulated map to
15241+
* be emitted. Sources that are infinite and never complete will never emit anything through this
15242+
* operator and an infinite source may lead to a fatal {@code OutOfMemoryError}.
1521515243
* <dl>
1521615244
* <dt><b>Backpressure:</b></dt>
1521715245
* <dd>The operator honors backpressure from downstream and consumes the source {@code Publisher} in an
@@ -15241,9 +15269,13 @@ public final <K, V> Single<Map<K, V>> toMap(final Function<? super T, ? extends
1524115269

1524215270
/**
1524315271
* Returns a Single that emits a single Map, returned by a specified {@code mapFactory} function, that
15244-
* contains keys and values extracted from the items emitted by the source Publisher.
15272+
* contains keys and values extracted from the items emitted by the finite source Publisher.
1524515273
* <p>
1524615274
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/toMap.png" alt="">
15275+
* <p>
15276+
* Note that this operator requires the upstream to signal {@code onComplete} for the accumulated map to
15277+
* be emitted. Sources that are infinite and never complete will never emit anything through this
15278+
* operator and an infinite source may lead to a fatal {@code OutOfMemoryError}.
1524715279
* <dl>
1524815280
* <dt><b>Backpressure:</b></dt>
1524915281
* <dd>The operator honors backpressure from downstream and consumes the source {@code Publisher} in an
@@ -15277,9 +15309,13 @@ public final <K, V> Single<Map<K, V>> toMap(final Function<? super T, ? extends
1527715309

1527815310
/**
1527915311
* Returns a Single that emits a single HashMap that contains an ArrayList of items emitted by the
15280-
* source Publisher keyed by a specified {@code keySelector} function.
15312+
* finite source Publisher keyed by a specified {@code keySelector} function.
1528115313
* <p>
1528215314
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/toMultiMap.png" alt="">
15315+
* <p>
15316+
* Note that this operator requires the upstream to signal {@code onComplete} for the accumulated map to
15317+
* be emitted. Sources that are infinite and never complete will never emit anything through this
15318+
* operator and an infinite source may lead to a fatal {@code OutOfMemoryError}.
1528315319
* <dl>
1528415320
* <dt><b>Backpressure:</b></dt>
1528515321
* <dd>This operator does not support backpressure as by intent it is requesting and buffering everything.</dd>
@@ -15306,10 +15342,14 @@ public final <K> Single<Map<K, Collection<T>>> toMultimap(Function<? super T, ?
1530615342

1530715343
/**
1530815344
* Returns a Single that emits a single HashMap that contains an ArrayList of values extracted by a
15309-
* specified {@code valueSelector} function from items emitted by the source Publisher, keyed by a
15345+
* specified {@code valueSelector} function from items emitted by the finite source Publisher, keyed by a
1531015346
* specified {@code keySelector} function.
1531115347
* <p>
1531215348
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/toMultiMap.png" alt="">
15349+
* <p>
15350+
* Note that this operator requires the upstream to signal {@code onComplete} for the accumulated map to
15351+
* be emitted. Sources that are infinite and never complete will never emit anything through this
15352+
* operator and an infinite source may lead to a fatal {@code OutOfMemoryError}.
1531315353
* <dl>
1531415354
* <dt><b>Backpressure:</b></dt>
1531515355
* <dd>The operator honors backpressure from downstream and consumes the source {@code Publisher} in an
@@ -15340,9 +15380,13 @@ public final <K, V> Single<Map<K, Collection<V>>> toMultimap(Function<? super T,
1534015380
/**
1534115381
* Returns a Single that emits a single Map, returned by a specified {@code mapFactory} function, that
1534215382
* contains a custom collection of values, extracted by a specified {@code valueSelector} function from
15343-
* items emitted by the source Publisher, and keyed by the {@code keySelector} function.
15383+
* items emitted by the finite source Publisher, and keyed by the {@code keySelector} function.
1534415384
* <p>
1534515385
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/toMultiMap.png" alt="">
15386+
* <p>
15387+
* Note that this operator requires the upstream to signal {@code onComplete} for the accumulated map to
15388+
* be emitted. Sources that are infinite and never complete will never emit anything through this
15389+
* operator and an infinite source may lead to a fatal {@code OutOfMemoryError}.
1534615390
* <dl>
1534715391
* <dt><b>Backpressure:</b></dt>
1534815392
* <dd>The operator honors backpressure from downstream and consumes the source {@code Publisher} in an
@@ -15383,9 +15427,13 @@ public final <K, V> Single<Map<K, Collection<V>>> toMultimap(
1538315427
/**
1538415428
* Returns a Single that emits a single Map, returned by a specified {@code mapFactory} function, that
1538515429
* contains an ArrayList of values, extracted by a specified {@code valueSelector} function from items
15386-
* emitted by the source Publisher and keyed by the {@code keySelector} function.
15430+
* emitted by the finite source Publisher and keyed by the {@code keySelector} function.
1538715431
* <p>
1538815432
* <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/toMultiMap.png" alt="">
15433+
* <p>
15434+
* Note that this operator requires the upstream to signal {@code onComplete} for the accumulated map to
15435+
* be emitted. Sources that are infinite and never complete will never emit anything through this
15436+
* operator and an infinite source may lead to a fatal {@code OutOfMemoryError}.
1538915437
* <dl>
1539015438
* <dt><b>Backpressure:</b></dt>
1539115439
* <dd>The operator honors backpressure from downstream and consumes the source {@code Publisher} in an
@@ -15437,7 +15485,7 @@ public final Observable<T> toObservable() {
1543715485
}
1543815486

1543915487
/**
15440-
* Returns a Single that emits a list that contains the items emitted by the source Publisher, in a
15488+
* Returns a Single that emits a list that contains the items emitted by the finite source Publisher, in a
1544115489
* sorted order. Each item emitted by the Publisher must implement {@link Comparable} with respect to all
1544215490
* other items in the sequence.
1544315491
*
@@ -15446,6 +15494,10 @@ public final Observable<T> toObservable() {
1544615494
* sequence is terminated with a {@link ClassCastException}.
1544715495
* <p>
1544815496
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/toSortedList.png" alt="">
15497+
* <p>
15498+
* Note that this operator requires the upstream to signal {@code onComplete} for the accumulated list to
15499+
* be emitted. Sources that are infinite and never complete will never emit anything through this
15500+
* operator and an infinite source may lead to a fatal {@code OutOfMemoryError}.
1544915501
* <dl>
1545015502
* <dt><b>Backpressure:</b></dt>
1545115503
* <dd>The operator honors backpressure from downstream and consumes the source {@code Publisher} in an
@@ -15465,10 +15517,14 @@ public final Single<List<T>> toSortedList() {
1546515517
}
1546615518

1546715519
/**
15468-
* Returns a Single that emits a list that contains the items emitted by the source Publisher, in a
15520+
* Returns a Single that emits a list that contains the items emitted by the finite source Publisher, in a
1546915521
* sorted order based on a specified comparison function.
1547015522
* <p>
1547115523
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/toSortedList.f.png" alt="">
15524+
* <p>
15525+
* Note that this operator requires the upstream to signal {@code onComplete} for the accumulated list to
15526+
* be emitted. Sources that are infinite and never complete will never emit anything through this
15527+
* operator and an infinite source may lead to a fatal {@code OutOfMemoryError}.
1547215528
* <dl>
1547315529
* <dt><b>Backpressure:</b></dt>
1547415530
* <dd>The operator honors backpressure from downstream and consumes the source {@code Publisher} in an
@@ -15493,10 +15549,14 @@ public final Single<List<T>> toSortedList(final Comparator<? super T> comparator
1549315549
}
1549415550

1549515551
/**
15496-
* Returns a Single that emits a list that contains the items emitted by the source Publisher, in a
15552+
* Returns a Single that emits a list that contains the items emitted by the finite source Publisher, in a
1549715553
* sorted order based on a specified comparison function.
1549815554
* <p>
1549915555
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/toSortedList.f.png" alt="">
15556+
* <p>
15557+
* Note that this operator requires the upstream to signal {@code onComplete} for the accumulated list to
15558+
* be emitted. Sources that are infinite and never complete will never emit anything through this
15559+
* operator and an infinite source may lead to a fatal {@code OutOfMemoryError}.
1550015560
* <dl>
1550115561
* <dt><b>Backpressure:</b></dt>
1550215562
* <dd>The operator honors backpressure from downstream and consumes the source {@code Publisher} in an
@@ -15524,7 +15584,7 @@ public final Single<List<T>> toSortedList(final Comparator<? super T> comparator
1552415584
}
1552515585

1552615586
/**
15527-
* Returns a Flowable that emits a list that contains the items emitted by the source Publisher, in a
15587+
* Returns a Flowable that emits a list that contains the items emitted by the finite source Publisher, in a
1552815588
* sorted order. Each item emitted by the Publisher must implement {@link Comparable} with respect to all
1552915589
* other items in the sequence.
1553015590
*
@@ -15533,6 +15593,10 @@ public final Single<List<T>> toSortedList(final Comparator<? super T> comparator
1553315593
* sequence is terminated with a {@link ClassCastException}.
1553415594
* <p>
1553515595
* <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/toSortedList.png" alt="">
15596+
* <p>
15597+
* Note that this operator requires the upstream to signal {@code onComplete} for the accumulated list to
15598+
* be emitted. Sources that are infinite and never complete will never emit anything through this
15599+
* operator and an infinite source may lead to a fatal {@code OutOfMemoryError}.
1553615600
* <dl>
1553715601
* <dt><b>Backpressure:</b></dt>
1553815602
* <dd>The operator honors backpressure from downstream and consumes the source {@code Publisher} in an

0 commit comments

Comments
 (0)