Packages

o

scala.compat.java8

StreamConverters

object StreamConverters extends StreamExtensions with 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 Steppers. 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 Steppers, including conversion to Scala collections with to or accumulation via accumulate. Steppers also implement seqStream and parStream to generate Streams. 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
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. StreamConverters
  2. Priority1AccumulatorConverters
  3. Priority2AccumulatorConverters
  4. Priority3AccumulatorConverters
  5. StreamExtensions
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. implicit class AnyArrayHasSeqParStream[A <: AnyRef] extends AnyRef
    Definition Classes
    StreamExtensions
  2. implicit class ByteArrayHasSeqParStream extends AnyRef
    Definition Classes
    StreamExtensions
  3. implicit class CharArrayHasSeqParStream extends AnyRef
    Definition Classes
    StreamExtensions
  4. implicit class DoubleArrayHasSeqParStream extends AnyRef
    Definition Classes
    StreamExtensions
  5. implicit class DoubleStreamHasToScala extends AnyRef
    Definition Classes
    StreamExtensions
  6. implicit class FloatArrayHasSeqParStream extends AnyRef
    Definition Classes
    StreamExtensions
  7. implicit class IntArrayHasSeqParStream extends AnyRef
    Definition Classes
    StreamExtensions
  8. implicit class IntStreamHasToScala extends AnyRef
    Definition Classes
    StreamExtensions
  9. implicit class IterableHasSeqStream[A] extends AnyRef
    Definition Classes
    StreamExtensions
  10. implicit class IterableNonGenericHasParStream[A, C <: collection.IterableOnce[_]] extends AnyRef
    Definition Classes
    StreamExtensions
  11. implicit class LongArrayHasSeqParStream extends AnyRef
    Definition Classes
    StreamExtensions
  12. implicit class LongStreamHasToScala extends AnyRef
    Definition Classes
    StreamExtensions
  13. implicit class MapHasParKeyValueStream[K, V, CC[X, Y] <: MapOps[X, Y, Map, _]] extends AnyRef
    Definition Classes
    StreamExtensions
  14. implicit class MapHasSeqKeyValueStream[K, V, CC[X, Y] <: MapOps[X, Y, Map, _]] extends AnyRef
    Definition Classes
    StreamExtensions
  15. implicit class ShortArrayHasSeqParStream extends AnyRef
    Definition Classes
    StreamExtensions
  16. implicit class StepperHasParStream[A] extends AnyRef
    Definition Classes
    StreamExtensions
  17. implicit class StepperHasSeqStream[A] extends AnyRef
    Definition Classes
    StreamExtensions
  18. implicit class StreamDoubleHasAccumulatePrimitive extends AnyRef
    Definition Classes
    StreamExtensions
  19. implicit class StreamHasToScala[A] extends AnyRef
    Definition Classes
    StreamExtensions
  20. implicit class StreamIntHasAccumulatePrimitive extends AnyRef
    Definition Classes
    StreamExtensions
  21. implicit class StreamJDoubleHasAccumulatePrimitive extends AnyRef
    Definition Classes
    StreamExtensions
  22. implicit class StreamJIntegerHasAccumulatePrimitive extends AnyRef
    Definition Classes
    StreamExtensions
  23. implicit class StreamJLongHasAccumulatePrimitive extends AnyRef
    Definition Classes
    StreamExtensions
  24. implicit class StreamLongHasAccumulatePrimitive extends AnyRef
    Definition Classes
    StreamExtensions

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. implicit def accumulateAnyArray[A](underlying: Array[A]): AccumulateAnyArray[A]
  5. implicit def accumulateDoubleArray(underlying: Array[Double]): AccumulateDoubleArray
  6. implicit def accumulateDoubleCollection(underlying: IterableOnce[Double]): AccumulateDoubleCollection
  7. implicit def accumulateIntArray(underlying: Array[Int]): AccumulateIntArray
  8. implicit def accumulateIntCollection(underlying: IterableOnce[Int]): AccumulateIntCollection
  9. implicit def accumulateLongArray(underlying: Array[Long]): AccumulateLongArray
  10. implicit def accumulateLongCollection(underlying: IterableOnce[Long]): AccumulateLongCollection
  11. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  12. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  13. implicit def collectionCanAccumulate[A](underlying: IterableOnce[A]): CollectionCanAccumulate[A]
  14. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  15. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  16. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  17. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  18. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  19. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  20. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  21. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  22. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  23. implicit def richDoubleStepper(s: Stepper[Double]): StepperExtensions[Double]
  24. implicit def richIntStepper(s: Stepper[Int]): StepperExtensions[Int]
  25. implicit def richLongStepper(s: Stepper[Long]): StepperExtensions[Long]
  26. implicit def richStepper[A](s: Stepper[A]): StepperExtensions[A]
    Definition Classes
    StreamExtensions
  27. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  28. def toString(): String
    Definition Classes
    AnyRef → Any
  29. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  30. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  31. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from StreamExtensions

Inherited from AnyRef

Inherited from Any

Ungrouped