Tabnine Logo
StreamUtils.stream
Code IndexAdd Tabnine to your IDE (free)

How to use
stream
method
in
com.aol.cyclops.streams.StreamUtils

Best Java code snippets using com.aol.cyclops.streams.StreamUtils.stream (Showing top 20 results out of 315)

origin: com.aol.cyclops/cyclops-core

/**
 * 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);
}
/**
origin: com.aol.cyclops/cyclops-core

/**
 * Create a stream from an iterable
 * 
 * @param it Iterable to convert to a Stream
 * @return Stream from iterable
 */
public static <U> Stream<U> stream(Iterable<U> it){
  return StreamUtils.stream(it);
}
/**
origin: com.aol.cyclops/cyclops-core

/**
 * Create a stream from an iterator
 * 
 * @param it Iterator to convert to a Stream
 * @return Stream from iterator
 */
public static <U> Stream<U> stream(Iterator<U> it){
  return StreamUtils.stream(it);
}

origin: com.aol.cyclops/cyclops-streams

  public Stream<T> limitLast(){
    Iterator<T> it = stream.iterator();
    return StreamUtils.stream(new Iterator<T>(){

      @Override
      public boolean hasNext() {
        while(it.hasNext()){
          buffer.add(it.next());
          if(buffer.size()>limit)
            buffer.pop();
        }
        return buffer.size()>0;
      }

      @Override
      public T next() {
        return buffer.pop();
      }
      
    });
  }
}
origin: com.aol.cyclops/cyclops-base

static <T> T unwrapOtherMonadTypes(Comprehender<T> comp,Object apply){
  
  if(apply instanceof LazySeq){
    return (T)StreamUtils.stream(((LazySeq)apply).iterator());
  }
  if(apply instanceof Iterable){
    return (T)StreamUtils.stream(((Iterable)apply));
  }
  if(apply instanceof Collection){
    return (T)((Collection)apply).stream();
  }
  
  return Comprehender.unwrapOtherMonadTypes(comp,apply);
  
}

origin: com.aol.cyclops/cyclops-base

/**
 * Construct a Sequence from an Iterable
 * @param iterable  to construct Sequence from
 * @return SequenceM
 */
public static <T> SequenceM<T> fromIterable(Iterable<T> iterable){
  return new SequenceM(StreamUtils.stream(iterable));
}
@Override
origin: com.aol.cyclops/cyclops-streams

public List zero(){
  return StreamUtils.stream(reducers).map(r->r.zero()).collect(Collectors.toList());
}
public BiFunction<List,List,List> combiner(){
origin: com.aol.cyclops/cyclops-base

public List zero(){
  return stream(reducers).map(r->r.zero()).collect(Collectors.toList());
}
public BiFunction<List,List,List> combiner(){
origin: com.aol.cyclops/cyclops-pattern-matching

public static Stream<Object> stream(Object t){

  if(t instanceof Iterable){
    return Stream.concat(StreamUtils.stream((Iterable)t).map(SeqUtils::nonNull),(StreamUtils.cycle(Stream.of(EMPTY))));
  }
  if(t instanceof Stream){
    return Stream.concat( ((Stream)t).map(SeqUtils::nonNull),(StreamUtils.cycle(Stream.of(EMPTY))));
  }
  if(t instanceof Iterator){
    return Stream.concat( StreamUtils.stream((Iterator)t).map(SeqUtils::nonNull),(StreamUtils.cycle(Stream.of(EMPTY))));
  }
  if(t instanceof Map){
    return Stream.concat(StreamUtils.stream((Map)t).map(SeqUtils::nonNull),(StreamUtils.cycle(Stream.of(EMPTY))));
  }
  return Stream.concat(Stream.of(t).map(SeqUtils::nonNull),(StreamUtils.cycle(Stream.of(EMPTY))));
}
origin: com.aol.cyclops/cyclops-core

public static <T> SortedSetX<T> fromIterable(Collector<T,?,SortedSet<T>>  collector,Iterable<T> it){
  if(it instanceof SortedSetX)
    return (SortedSetX)it;
  if(it instanceof SortedSet)
    return new SortedSetXImpl<T>( (SortedSet)it, collector);
  return new SortedSetXImpl<T>(StreamUtils.stream(it).collect(collector),collector);
}

origin: com.aol.cyclops/cyclops-core

public static <T> DequeX<T> fromIterable(Collector<T,?,Deque<T>>  collector,Iterable<T> it){
  if(it instanceof DequeX)
    return (DequeX)it;
  if(it instanceof Deque)
    return new DequeXImpl<T>( (Deque)it, collector);
  return new DequeXImpl<T>(StreamUtils.stream(it).collect(collector),collector);
}

origin: com.aol.cyclops/cyclops-streams

/**
 * <pre>
 * {@code 
 *  Stream<String> helloWorld = Stream.of();
  Optional<HeadAndTail<String>> headAndTail = StreamUtils.headAndTailOptional(helloWorld);
  assertTrue(!headAndTail.isPresent());
 * }
 * </pre>
 * @param stream to extract head and tail from
 * @return
 */
public final  static <T> Optional<HeadAndTail<T>> headAndTailOptional(Stream<T> stream){
  Iterator<T> it = stream.iterator();
  if(!it.hasNext())
    return Optional.empty();
  return Optional.of(new HeadAndTail(it.next(),sequenceM(stream(it),Optional.empty())));
}

origin: com.aol.cyclops/cyclops-core

public static <T> QueueX<T> fromIterable(Collector<T,?,Queue<T>>  collector,Iterable<T> it){
  if(it instanceof QueueX)
    return (QueueX)it;
  if(it instanceof Deque)
    return new QueueXImpl<T>( (Queue)it, collector);
  return new QueueXImpl<T>(StreamUtils.stream(it).collect(collector),collector);
}

origin: com.aol.cyclops/cyclops-core

public static <T> SetX<T> fromIterable(Collector<T,?,Set<T>>  collector,Iterable<T> it){
  if(it instanceof SetX)
    return (SetX)it;
  if(it instanceof Set)
    return new SetXImpl<T>( (Set)it, collector);
  return new SetXImpl<T>(StreamUtils.stream(it).collect(collector),collector);
}
@Override
origin: com.aol.cyclops/cyclops-core

public static <T> ListX<T> fromIterable(Collector<T,?,List<T>>  collector,Iterable<T> it){
  if(it instanceof ListX)
    return (ListX)it;
  if(it instanceof List)
    return new ListXImpl<T>( (List)it, collector);
  return new ListXImpl<T>(StreamUtils.stream(it).collect(collector),collector);
}
@Override
origin: com.aol.cyclops/cyclops-base

/**
 * flatMap operation
 * 
 * <pre>
 * {@code 
 *     assertThat(anyM(Stream.of(1,2,3)).asSequence().flatMapStream(i->Stream.of(i)).toList(),equalTo(Arrays.asList(1,2,3)));
 * }
 * </pre>
 * 
 * @param fn to be applied
 * @return new stage in Sequence with flatMap operation to be lazily applied
*/
public final <R> SequenceM<R> flatMapStream(Function<? super T,BaseStream<? extends R,?>> fn) {
  return new SequenceM<>(monad.flatMap( in->StreamUtils.stream(fn.apply(in).iterator())));
}
/**
origin: com.aol.cyclops/cyclops-streams

private final static <T> Tuple2<Stream<T>,Stream<T>> duplicatePos(Stream<T> stream,int pos){
  
  Tuple2<Iterator<T>,Iterator<T>> Tuple2 = StreamUtils.toBufferingDuplicator(stream.iterator(),pos);    
  return new Tuple2(StreamUtils.stream(Tuple2.v1()),StreamUtils.stream(Tuple2.v2()));
}
/**
origin: com.aol.cyclops/cyclops-base

/**
 * <pre>
 * {@code 
 *  Stream<String> helloWorld = Stream.of();
  Optional<HeadAndTail<String>> headAndTail = StreamUtils.headAndTailOptional(helloWorld);
  assertTrue(!headAndTail.isPresent());
 * }
 * </pre>
 * @param stream to extract head and tail from
 * @return
 */
public final  static <T> Optional<HeadAndTail<T>> headAndTailOptional(Stream<T> stream){
  Iterator<T> it = stream.iterator();
  if(!it.hasNext())
    return Optional.empty();
  return Optional.of(new HeadAndTail(it.next(),AsAnyM.anyM(stream(it)).asSequence()));
}

origin: com.aol.cyclops/cyclops-streams

/**
 * Duplicate a Stream, buffers intermediate values, leaders may change positions so a limit
 * can be safely applied to the leading stream. Not thread-safe.
 * <pre>
 * {@code 
 *  Tuple2<SequenceM<Integer>, SequenceM<Integer>> copies =of(1,2,3,4,5,6).duplicate();
   assertTrue(copies.v1.anyMatch(i->i==2));
   assertTrue(copies.v2.anyMatch(i->i==2));
 * 
 * }
 * </pre>
 * 
 * @return duplicated stream
 */
public final static <T> Tuple2<Stream<T>,Stream<T>> duplicate(Stream<T> stream){
  
  Tuple2<Iterator<T>,Iterator<T>> Tuple2 = StreamUtils.toBufferingDuplicator(stream.iterator());    
  return new Tuple2(StreamUtils.stream(Tuple2.v1()),StreamUtils.stream(Tuple2.v2()));
}
private final static <T> Tuple2<Stream<T>,Stream<T>> duplicatePos(Stream<T> stream,int pos){
origin: com.aol.cyclops/cyclops-base

private final Pair<SequenceM<T>,SequenceM<T>> duplicatePos(int pos){
  
  Pair<Iterator<T>,Iterator<T>> pair = StreamUtils.toBufferingDuplicator(monad.iterator(),pos);    
  return new Pair(new SequenceM(StreamUtils.stream(pair._1())),new SequenceM(StreamUtils.stream(pair._2())));
}
/**
com.aol.cyclops.streamsStreamUtilsstream

Javadoc

Create a stream from an iterable
 
 

Popular methods of StreamUtils

  • cycle
    Convert to a Stream with the result of a reduction operation repeated specified times
  • collect
    Apply multiple Collectors, simultaneously to a Stream
  • reduce
    Simultanously reduce a stream with multiple reducers
  • reverse
    Reverse a Stream
  • reversedStream
    Create a reversed Stream from a List
  • completableFutureToStream
  • concat
    Concat an Object and a Stream If the Object is a Stream, Streamable or Iterable will be converted (o
  • forEachEvent
    Perform a forEach operation over the Stream capturing any elements and errors in the supplied consum
  • forEachWithError
    Perform a forEach operation over the Stream capturing any elements and errors in the supplied consum
  • forEachX
    Perform a forEach operation over the Stream, without closing it, consuming only the specified number
  • forEachXEvents
    Perform a forEach operation over the Stream without closing it, capturing any elements and errors in
  • forEachXWithError
    Perform a forEach operation over the Stream without closing it, capturing any elements and errors in
  • forEachXEvents,
  • forEachXWithError,
  • headAndTail,
  • headAndTailOptional,
  • join,
  • limitUntil,
  • limitWhile,
  • max,
  • maxBy

Popular in Java

  • Making http post requests using okhttp
  • onRequestPermissionsResult (Fragment)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • getSharedPreferences (Context)
  • BigDecimal (java.math)
    An immutable arbitrary-precision signed decimal.A value is represented by an arbitrary-precision "un
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • List (java.util)
    An ordered collection (also known as a sequence). The user of this interface has precise control ove
  • ReentrantLock (java.util.concurrent.locks)
    A reentrant mutual exclusion Lock with the same basic behavior and semantics as the implicit monitor
  • Logger (org.slf4j)
    The org.slf4j.Logger interface is the main user entry point of SLF4J API. It is expected that loggin
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now