public class StreamConverters$ extends java.lang.Object implements Priority1StreamConverters, Priority1StepConverters, Priority1AccumulatorConverters
StreamConverters
provides extension methods and other functionality to
ease interoperability of Scala collections with java.util.stream
classes.
Scala collections gain extension methods seqStream
and
parStream
that allow them to be used as the source of a Stream
.
Some collections either intrinsically cannot be paralellized, or
could be but an efficient implementation is missing. It this case,
only seqStream
is provided. If a collection cannot be stepped over
at all (e.g. Traversable
), then it gains neither method.
Array
also gains seqStream
and parStream
methods, and calling those
on Array[Double]
, Array[Int]
, or Array[Long]
will produce the
corresponding primitive stream.
Streams gain accumulate
and toScala[_]
methods, which collect the stream
into a custom high-performance scala.collection.mutable.java8.Accumulator
,
which is not part of the standard collections hierarchy, or into a named
Scala collection, respectively.
Generic streams also gain an unboxed
method that will convert to the
corresponding unboxed primitive stream, if appropriate. Unboxed streams
have custom accumulators with improved performance.
Accumulators have toArray
, toList
, iterator
, and to[_]
methods
to convert to standard Scala collections. Note that if you wish to
create an array from a Stream
, going through an Accumulator
is
not the most efficient option: just create the Array
directly.
Internally, Scala collections implement a hybrid of Iterator
and
java.util.Spliterator
to implement Stream
compatibility; these
are called Stepper
s. In particular, they can test for the presence
of a next element using hasStep
, can retrieve the next value with
nextStep
, or can optionally retrieve and operate on a value if present
with tryStep
, which works like tryAdvance
in java.util.Spliterator
.
Every Scala collection that can be stepped
through has a stepper
method implicitly provided. In addition,
maps have keyStepper
and valueStepper
methods. A limited number
of collections operations are defined on Stepper
s, including conversion
to Scala collections with to
or accumulation via accumulate
.
Stepper
s also implement seqStream
and parStream
to generate Stream
s.
These are provided regardless of whether a Stepper
can efficiently
subdivide itself for parallel processing (though one can check for the
presence of the EfficientSubstep
trait to know that parallel execution will
not be limited by long sequential searching steps, and one can call
anticipateParallelism
to warn a Stepper
that it will be used in a parallel
context and thus may wish to make different tradeoffs).
Examples:
import scala.compat.java8.StreamConverters._
val s = Vector(1,2,3,4).parStream // Stream[Int]
val si = s.unboxed // Stream.OfInt
val ai = si.accumulate // IntAccumulator
val v = ai.to[Vector] // Vector[Int] again
val t = Array(2.0, 3.0, 4.0).parStream // DoubleStream
val q = t.toScala[scala.collection.immutable.Queue] // Queue[Double]
val x = List(1L, 2L, 3L, 4L).stepper.parStream.sum // 10, potentially computed in parallel
Priority1StreamConverters.RichStream<A>, Priority1StreamConverters.RichStreamCanAccumulatePrimitive<S>
Priority2StreamConverters.EnrichAnySteppableWithParKeyStream<A,S extends java.util.stream.BaseStream<?,S>,CC>, Priority2StreamConverters.EnrichAnySteppableWithParStream<A,S extends java.util.stream.BaseStream<?,S>,CC>, Priority2StreamConverters.EnrichAnySteppableWithParValueStream<A,S extends java.util.stream.BaseStream<?,S>,CC>, Priority2StreamConverters.EnrichAnySteppableWithSeqStream<A,S extends java.util.stream.BaseStream<?,S>,CC>, Priority2StreamConverters.EnrichScalaCollectionWithSeqKeyStream<A,S extends java.util.stream.BaseStream<?,S>,CC>, Priority2StreamConverters.EnrichScalaCollectionWithSeqValueStream<A,S extends java.util.stream.BaseStream<?,S>,CC>
Modifier and Type | Field and Description |
---|---|
static StreamConverters$ |
MODULE$
Static reference to the singleton instance of this Scala object.
|
Constructor and Description |
---|
StreamConverters$() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
richArrayCanStep, richBitSetCanStep, richDefaultHashTableCanStep, richFlatHashTableCanStep, richImmHashMapCanStep, richImmHashSetCanStep, richIteratorCanStep, richLinkedHashTableCanStep, richNumericRangeCanStep, richRangeCanStep, richStringCanStep, richVectorCanStep, richWrappedArrayCanStep
richIndexedSeqCanStep, richLinearSeqCanStep
richIterableCanStep, richMapCanStep
accumulateAnyStepper, accumulateDoubleArray, accumulateIntArray, accumulateLongArray
accumulateAnyArray, accumulateDoubleCollection, accumulateIntCollection, accumulateLongCollection
collectionCanAccumulate
public static final StreamConverters$ MODULE$
public java.lang.Object primitiveAccumulateDoubleStream()
public PrimitiveStreamAccumulator<java.util.stream.Stream<java.lang.Double>,DoubleAccumulator> primitiveAccumulateDoubleStream2()
public java.lang.Object primitiveUnboxDoubleStream()
public PrimitiveStreamUnboxer<java.lang.Double,java.util.stream.DoubleStream> primitiveUnboxDoubleStream2()
public java.lang.Object primitiveAccumulateIntStream()
public PrimitiveStreamAccumulator<java.util.stream.Stream<java.lang.Integer>,IntAccumulator> primitiveAccumulateIntStream2()
public java.lang.Object primitiveUnboxIntStream()
public PrimitiveStreamUnboxer<java.lang.Integer,java.util.stream.IntStream> primitiveUnboxIntStream2()
public java.lang.Object primitiveAccumulateLongStream()
public PrimitiveStreamAccumulator<java.util.stream.Stream<java.lang.Long>,LongAccumulator> primitiveAccumulateLongStream2()
public java.lang.Object primitiveUnboxLongStream()
public PrimitiveStreamUnboxer<java.lang.Long,java.util.stream.LongStream> primitiveUnboxLongStream2()
public java.lang.Object accumulateDoubleStepper()
public java.lang.Object accumulateIntStepper()
public java.lang.Object accumulateLongStepper()