|
17 | 17 |
|
18 | 18 | import static javaemul.internal.InternalPreconditions.checkState; |
19 | 19 |
|
| 20 | +import java.util.ArrayList; |
20 | 21 | import java.util.Arrays; |
21 | 22 | import java.util.Collections; |
| 23 | +import java.util.List; |
22 | 24 | import java.util.Comparator; |
23 | 25 | import java.util.Optional; |
24 | 26 | import java.util.Spliterator; |
|
28 | 30 | import java.util.function.BiFunction; |
29 | 31 | import java.util.function.BinaryOperator; |
30 | 32 | import java.util.function.Consumer; |
| 33 | +import java.util.function.DoubleConsumer; |
31 | 34 | import java.util.function.Function; |
| 35 | +import java.util.function.IntConsumer; |
32 | 36 | import java.util.function.IntFunction; |
| 37 | +import java.util.function.LongConsumer; |
33 | 38 | import java.util.function.Predicate; |
34 | 39 | import java.util.function.Supplier; |
35 | 40 | import java.util.function.ToDoubleFunction; |
@@ -327,6 +332,38 @@ public boolean tryAdvance(Consumer<? super T> action) { |
327 | 332 | return StreamSupport.stream(spliterator, false); |
328 | 333 | } |
329 | 334 |
|
| 335 | + default public <R> Stream<R> mapMulti(BiConsumer<T, Consumer<? super R>> mapper) { |
| 336 | + return flatMap(element -> { |
| 337 | + List<R> buffer = new ArrayList<>(); |
| 338 | + mapper.accept(element, buffer::add); |
| 339 | + return buffer.stream(); |
| 340 | + }); |
| 341 | + } |
| 342 | + |
| 343 | + default DoubleStream mapMultiToDouble(BiConsumer<? super T, ? super DoubleConsumer> mapper) { |
| 344 | + return flatMapToDouble(element -> { |
| 345 | + List<Double> buffer = new ArrayList<>(); |
| 346 | + mapper.accept(element, buffer::add); |
| 347 | + return buffer.stream().mapToDouble(n -> n); |
| 348 | + }); |
| 349 | + } |
| 350 | + |
| 351 | + default IntStream mapMultiToInt(BiConsumer<? super T, ? super IntConsumer> mapper) { |
| 352 | + return flatMapToInt(element -> { |
| 353 | + List<Integer> buffer = new ArrayList<>(); |
| 354 | + mapper.accept(element, buffer::add); |
| 355 | + return buffer.stream().mapToInt(n -> n); |
| 356 | + }); |
| 357 | + } |
| 358 | + |
| 359 | + default LongStream mapMultiToLong(BiConsumer<? super T, ? super LongConsumer> mapper) { |
| 360 | + return flatMapToLong(element -> { |
| 361 | + List<Long> buffer = new ArrayList<>(); |
| 362 | + mapper.accept(element, buffer::add); |
| 363 | + return buffer.stream().mapToLong(n -> n); |
| 364 | + }); |
| 365 | + } |
| 366 | + |
330 | 367 | Object[] toArray(); |
331 | 368 |
|
332 | 369 | <A> A[] toArray(IntFunction<A[]> generator); |
|
0 commit comments