|
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,41 @@ 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 | + DoubleConsumer consumer = buffer::add; |
| 347 | + mapper.accept(element, consumer); |
| 348 | + return buffer.stream().mapToDouble(n -> n); |
| 349 | + }); |
| 350 | + } |
| 351 | + |
| 352 | + default IntStream mapMultiToInt(BiConsumer<? super T, ? super IntConsumer> mapper) { |
| 353 | + return flatMapToInt(element -> { |
| 354 | + List<Integer> buffer = new ArrayList<>(); |
| 355 | + IntConsumer consumer = buffer::add; |
| 356 | + mapper.accept(element, consumer); |
| 357 | + return buffer.stream().mapToInt(n -> n); |
| 358 | + }); |
| 359 | + } |
| 360 | + |
| 361 | + default LongStream mapMultiToLong(BiConsumer<? super T, ? super LongConsumer> mapper) { |
| 362 | + return flatMapToLong(element -> { |
| 363 | + List<Long> buffer = new ArrayList<>(); |
| 364 | + LongConsumer consumer = buffer::add; |
| 365 | + mapper.accept(element, consumer); |
| 366 | + return buffer.stream().mapToLong(n -> n); |
| 367 | + }); |
| 368 | + } |
| 369 | + |
330 | 370 | Object[] toArray();
|
331 | 371 |
|
332 | 372 | <A> A[] toArray(IntFunction<A[]> generator);
|
|
0 commit comments