/** * @return Streamable that replay this SequenceM */ public Streamable<T> toConcurrentLazyStreamable(){ return AsStreamable.asConcurrentStreamable(monad); } public SequenceM<T> reverse(){
/** * @return Underlying monad converted to a Streamable instance */ public final static <T> Streamable<T> toStreamable(Stream<T> stream){ return AsStreamable.asStreamable(stream); } /**
/** * @param toCoerce Efficiently / lazily Makes Stream repeatable, not thread safe, on initial iteration * @return */ public static <T> Streamable<T> asStreamable(Stream<T> toCoerce){ return new CoercedStreamable(collectStream(toCoerce)); } public static <T> Streamable<T> asStreamable(Iterable<T> toCoerce){
/** * @param toCoerce Efficiently / lazily Makes Stream repeatable, guards iteration with locks on initial iteration * @return */ public static <T> Streamable<T> asConcurrentStreamable(Stream<T> toCoerce){ return new CoercedStreamable(collectStreamConcurrent(toCoerce)); } public static <T> Streamable<T> asConcurrentStreamable(Iterable<T> toCoerce){
public static <T> Streamable<T> asStreamable(Object toCoerce){ return new CoercedStreamable(collectStream(toCoerce)); } /**
public static <T> Streamable<T> asConcurrentStreamable(Iterable<T> toCoerce){ return new CoercedStreamable(collectStreamConcurrent(toCoerce)); }
/** * (Lazily) Construct a Streamable from an Iterable. * * @param iterable to construct Streamable from * @return Streamable */ public static <T> Streamable<T> fromIterable(Iterable<T> iterable){ return AsStreamable.asStreamable(iterable); } /**
public static <T> Streamable<T> asStreamable(Iterable<T> toCoerce){ return new CoercedStreamable(collectStream(toCoerce)); } /**
/** * (Lazily) Construct a Streamable from a Stream. * * @param stream to construct Streamable from * @return Streamable */ public static <T> Streamable<T> fromStream(Stream<T> stream){ return AsStreamable.asStreamable(stream); } /**
/** * @return Streamable that can replay this SequenceM */ public Streamable<T> toLazyStreamable(){ return AsStreamable.asStreamable(monad); } /**
/** * @return Underlying monad converted to a Streamable instance */ public final Streamable<T> toStreamable(){ return AsStreamable.asStreamable(stream()); } /**
/** * Create a new Stream that infiniteable cycles the provided Stream * * <pre> * {@code * assertThat(StreamUtils.cycle(Stream.of(1,2,3)) * .limit(6) * .collect(Collectors.toList()), * equalTo(Arrays.asList(1,2,3,1,2,3))); } * </pre> * @param s Stream to cycle * @return New cycling stream */ public static <U> Stream<U> cycle(Stream<U> s){ return cycle(AsStreamable.asStreamable(s)); } /**
/** * Apply multiple Collectors, simultaneously to a Stream * <pre> * {@code * List result = StreamUtils.collect(Stream.of(1,2,3), Arrays.asList(Collectors.toList(), Collectors.summingInt(Integer::intValue), Collectors.averagingInt(Integer::intValue))); assertThat(result.get(0),equalTo(Arrays.asList(1,2,3))); assertThat(result.get(1),equalTo(6)); assertThat(result.get(2),equalTo(2.0)); * } * </pre> * @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 collect(stream, AsStreamable.<Collector>asStreamable(collectors)); } /**
/** * Apply multiple Collectors, simultaneously to a Stream * <pre> * {@code * List result = StreamUtils.collect(Stream.of(1,2,3), Stream.of(Collectors.toList(), Collectors.summingInt(Integer::intValue), Collectors.averagingInt(Integer::intValue))); assertThat(result.get(0),equalTo(Arrays.asList(1,2,3))); assertThat(result.get(1),equalTo(6)); assertThat(result.get(2),equalTo(2.0)); * } * </pre> * @param stream Stream to collect * @param collectors Collectors to apply * @return Result as a list */ public static <T,A,R> List<R> collect(Stream<T> stream, Stream<Collector> collectors){ return collect(stream, AsStreamable.<Collector>asStreamable(collectors)); } /**
/** * Convert to a Stream with the values repeated specified times * * <pre> * {@code * assertThat(anyM(Stream.of(1,2,2)).asSequence() .cycle(3).collect(Collectors.toList()), equalTo(Arrays.asList(1,2,2,1,2,2,1,2,2))); * * } * </pre> * @param times * Times values should be repeated within a Stream * @return Stream with values repeated */ public final SequenceM<T> cycle(int times) { return new SequenceM(StreamUtils.cycle(times,AsStreamable.asStreamable(monad))); } /**
/** * Convert to a Stream with the result of a reduction operation repeated * specified times * * <pre> * {@code * List<Integer> list = StreamUtils.cycle(Stream.of(1,2,2),Reducers.toCountInt(),3) * . * .collect(Collectors.toList()); * //is asList(3,3,3); * } * </pre> * * @param m * Monoid to be used in reduction * @param times * Number of times value should be repeated * @return Stream with reduced values repeated */ public final static <T> Stream<T> cycle(Stream<T> stream,Monoid<T> m, int times) { return StreamUtils.cycle(times,AsStreamable.asStreamable(m.reduce(stream))); }
/** * Convert to a Stream with the values repeated specified times * * @param times Times values should be repeated within a Stream * @return Stream with values repeated */ default Monad<Stream<T>,T> cycle(int times){ return monad(StreamUtils.cycle(times,AsStreamable.asStreamable(stream()))); } @Override
/** * Convert to a Stream with the result of a reduction operation repeated * specified times * * <pre> * {@code * List<Integer> list = AsGenericMonad,asMonad(Stream.of(1,2,2)) * .cycle(Reducers.toCountInt(),3) * .collect(Collectors.toList()); * //is asList(3,3,3); * } * </pre> * * @param m * Monoid to be used in reduction * @param times * Number of times value should be repeated * @return Stream with reduced values repeated */ public final SequenceM<T> cycle(Monoid<T> m, int times) { return monad(StreamUtils.cycle(times,AsStreamable.asStreamable(m.reduce(monad)))); }