Add GroupedWeighted FlowOp and Make Grouped use GroupedWeighted #29066
This commit is contained in:
parent
dffd7099fd
commit
4d9b25579d
18 changed files with 351 additions and 30 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue