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; }
private static <T> T collectStream(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; } @Value
public static final <A> Collection<A> toLazyCollection(Iterator<A> iterator){ return toLazyCollection(iterator,false); } /**
public static final <A> Collection<A> toConcurrentLazyCollection(Iterator<A> iterator){ return toLazyCollection(iterator,true); } private static final <A> Collection<A> toLazyCollection(Iterator<A> iterator,boolean concurrent) {
/** * Lazily converts this SequenceM into a Collection. This does not trigger the Stream. E.g. * Collection is not thread safe on the first iteration. * <pre> * {@code * Collection<Integer> col = SequenceM.of(1,2,3,4,5) .peek(System.out::println) .toLazyCollection(); System.out.println("first!"); col.forEach(System.out::println); * } * * //Will print out "first!" before anything else * </pre> * @return */ public Collection<T> toLazyCollection(){ return StreamUtils.toLazyCollection(stream); } /**
/** * Lazily converts this SequenceM into a Collection. This does not trigger the Stream. E.g. * Collection is not thread safe on the first iteration. * <pre> * {@code * Collection<Integer> col = SequenceM.of(1,2,3,4,5) .peek(System.out::println) .toLazyCollection(); System.out.println("first!"); col.forEach(System.out::println); * } * * //Will print out "first!" before anything else * </pre> * @return */ public Collection<T> toLazyCollection(){ return StreamUtils.toLazyCollection(monad); } /**
/** * Projects an immutable collection of this stream. Initial iteration over the collection is not thread safe * (can't be performed by multiple threads concurrently) subsequent iterations are. * * @return An immutable collection of this stream. */ public static final <A> Collection<A> toLazyCollection(Stream<A> stream) { return toLazyCollection(stream.iterator()); } public static final <A> Collection<A> toLazyCollection(Iterator<A> iterator){