Class RStreams

java.lang.Object
uk.co.terminological.rjava.utils.RStreams

public class RStreams extends Object
The Class Java8Streams can be statically imported and allows any type to be flatMapped. e.g. streamOfMaybeListsContainingNullValues.flatMap(l -> maybe(l.getOptionalValue()));
Version:
$Id: $Id
Author:
vp22681
  • Constructor Details

    • RStreams

      public RStreams()
  • Method Details

    • maybe

      @SafeVarargs public static <T> Stream<T> maybe(T... t)
      Create a stream from a potentially null singleton or array
      Type Parameters:
      T - any type
      Parameters:
      t - a set of values
      Returns:
      a stream
    • maybe

      public static <T> Stream<T> maybe(Collection<T> list)
      Create a stream from a potentially null collection
      Type Parameters:
      T - any type
      Parameters:
      list - a collection of values
      Returns:
      a stream
    • maybe

      public static <T> Stream<T> maybe(Stream<T> stream)
      Create a stream from a potentially null stream
      Type Parameters:
      T - any type
      Parameters:
      stream - a stream
      Returns:
      a stream
    • maybe

      public static <T> Stream<T> maybe(Optional<T> t)
      Create a stream from a potentially null optional
      Type Parameters:
      T - any type
      Parameters:
      t - an optional value
      Returns:
      a stream
    • maybe

      public static <T> Stream<T> maybe(Iterable<T> iter)
      Create a stream from a potentially null iterable
      Type Parameters:
      T - any type
      Parameters:
      iter - an iterable of values
      Returns:
      a stream
    • maybe

      public static <T> Stream<T> maybe(Iterator<T> iter)
      Create a stream from a potentially null iterator
      Type Parameters:
      T - any type
      Parameters:
      iter - an iterator
      Returns:
      a stream
    • maybe

      public static <T> Stream<T> maybe(RPrimitive t)
      Create a stream from a potentially null or NA valued RPrimitive
      Type Parameters:
      T - any type
      Parameters:
      t - an RPrimitive
      Returns:
      a stream of the underlying java object omitting NA values
    • maybe

      public static <U extends RPrimitive, T> Stream<T> maybe(RVector<U> t)
      Create a stream from a potentially null or NA valued RVector
      Type Parameters:
      T - any type
      U - an RPrimitive
      Parameters:
      t - an RVector of type U
      Returns:
      a stream of the underlying java object omitting NA values
    • deferError

      public static <T, R> Function<T,RStreams.Exceptional<R>> deferError(RStreams.ExceptionalFunction<T,R> fn)

      deferError.

      Type Parameters:
      T - a T class
      R - a R class
      Parameters:
      fn - a RStreams.ExceptionalFunction object
      Returns:
      a Function object