Java 16's `Stream::mapMulti` can theoretically simulate a reverse-flatMap (grouping) operation, but both approaches have significant shortcomings. The 'late emitting' approach fails to emit the last group if it doesn't reach the required size. The 'early emitting' approach requires mutable group objects and conflicts with Stream's element-by-element processing model, causing downstream operations to see incomplete groups. The only reliable use case is sequential parsing where group boundaries are deterministic (e.g., JSON blocks ending with `}`). Parallel streams break both approaches entirely. The conclusion is that `mapMulti` is not a general-purpose grouping solution.
Sort: