/** * Reduce with multiple reducers in parallel * NB if this Monad is an Optional [Arrays.asList(1,2,3)] reduce will operate on the Optional as if the list was one value * To reduce over the values on the list, called streamedStreamUtils.sequenceM() first. I.e. streamedStreamUtils.sequenceM().reduce(reducer) * * @param reducers * @return */ public final List<T> reduce(Iterable<Monoid<T>> reducers){ return StreamUtils.reduce(stream, reducers); }
@Override public<C extends Collection<? super T>> SequenceM<C> batchWhile(Predicate<? super T> predicate, Supplier<C> factory) { return StreamUtils.sequenceM(StreamUtils.batchWhile(stream,predicate,factory), this.reversable); } @Override
/** * Create a stream from a map * * @param it Iterator to convert to a Stream * @return Stream from a map */ public static <K,V> Stream<Map.Entry<K, V>> stream(Map<K,V> it){ return StreamUtils.stream(it); } /**
/** * Apply multiple Collectors, simultaneously to a Stream * * @param stream Stream to collect * @param collectors Collectors to apply * @return Result as a list */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static <T,A,R> List<R> collect(Stream<T> stream, Iterable<Collector> collectors){ return StreamUtils.collect(stream, collectors); } /**
@Override public <C extends Collection<T>> SequenceM<C> batchByTime(long time, TimeUnit unit, Supplier<C> factory) { return StreamUtils.sequenceM(StreamUtils.batchByTime(stream, time, unit, factory),this.reversable); } @Override
public <X extends Throwable> void forEachEvent(Consumer<? super T> consumerElement, Consumer<? super Throwable> consumerError, Runnable onComplete){ StreamUtils.forEachEvent(this, consumerElement, consumerError, onComplete); }
@Override public <X extends Throwable> org.reactivestreams.Subscription forEachXWithError( long numberOfElements, Consumer<? super U> consumer, Consumer<? super Throwable> consumerError) { return StreamUtils.forEachXWithError(this, numberOfElements,consumer, consumerError); } @Override
@Override public <X extends Throwable> void forEachWithError( Consumer<? super U> consumerElement, Consumer<? super Throwable> consumerError) { StreamUtils.forEachWithError(this, consumerElement, consumerError); } @Override
/** * Extract the minimum as determined by supplied function * */ public final <U extends Comparable<? super U>> Optional<T> minBy(Function<? super T, ? extends U> function){ return StreamUtils.minBy(stream,function); } /* (non-Javadoc)
@Override public <C extends Collection<T>> SequenceM<C> batchBySize(int size, Supplier<C> factory) { return StreamUtils.sequenceM(StreamUtils.batchBySize(stream, size,factory),this.reversable); }
private static <T> T collectStreamConcurrent(T object){ if(object instanceof Stream){ Collection c = StreamUtils.toLazyCollection((Stream)object); return (T)new Iterable(){ @Override public Iterator iterator() { return c.iterator(); } }; } return object; }
/** * @return Streamable that replay this SequenceM */ public Streamable<T> toConcurrentLazyStreamable(){ return StreamUtils.toConcurrentLazyStreamable(stream); } public SequenceM<T> reverse(){
/** * Reduce with multiple reducers in parallel * NB if this Monad is an Optional [Arrays.asList(1,2,3)] reduce will operate on the Optional as if the list was one value * To reduce over the values on the list, called streamedStreamUtils.sequenceM() first. I.e. streamedStreamUtils.sequenceM().reduce(reducer) * * @param reducers * @return */ public final List<T> reduce(Stream<? extends Monoid<T>> reducers){ return StreamUtils.reduce(stream, reducers); } /**
@Override public List collectStream(Stream<Collector> collectors) { return StreamUtils.collect(stream,collectors); } @Override
@Override public SequenceM<List<T>> batchWhile(Predicate<? super T> predicate) { return StreamUtils.sequenceM(StreamUtils.batchWhile(stream,predicate), this.reversable); } @Override