Add GroupedWeighted FlowOp and Make Grouped use GroupedWeighted #29066

This commit is contained in:
Michael Marshall 2021-01-27 10:03:30 -07:00 committed by GitHub
parent dffd7099fd
commit 4d9b25579d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 351 additions and 30 deletions

View file

@ -371,6 +371,26 @@ class SubSource[Out, Mat](
def grouped(n: Int): SubSource[java.util.List[Out @uncheckedVariance], Mat] =
new SubSource(delegate.grouped(n).map(_.asJava)) // TODO optimize to one step
/**
* Chunk up this stream into groups of elements that have a cumulative weight greater than or equal to
* the `minWeight`, with the last group possibly smaller than requested `minWeight` due to end-of-stream.
*
* `minWeight` must be positive, otherwise IllegalArgumentException is thrown.
* `costFn` must return a non-negative result for all inputs, otherwise the stage will fail
* with an IllegalArgumentException.
*
* '''Emits when''' the cumulative weight of elements is greater than or equal to the `minWeight` or upstream completed
*
* '''Backpressures when''' a buffered group weighs more than `minWeight` and downstream backpressures
*
* '''Completes when''' upstream completes
*
* '''Cancels when''' downstream cancels
*/
def groupedWeighted(minWeight: Long)(
costFn: function.Function[Out, java.lang.Long]): SubSource[java.util.List[Out @uncheckedVariance], Mat] =
new SubSource(delegate.groupedWeighted(minWeight)(costFn.apply).map(_.asJava)) // TODO optimize to one step
/**
* Apply a sliding window over the stream and return the windows as groups of elements, with the last group
* possibly smaller than requested due to end-of-stream.