diff --git a/src/main/scala/scala/compat/java8/StreamConverters.scala b/src/main/scala/scala/compat/java8/StreamConverters.scala index 55e8bc9..36afc19 100644 --- a/src/main/scala/scala/compat/java8/StreamConverters.scala +++ b/src/main/scala/scala/compat/java8/StreamConverters.scala @@ -210,16 +210,16 @@ trait StreamExtensions { // toScala for streams implicit class StreamHasToScala[A](stream: Stream[A]) { - def accumulate: AnyAccumulator[A] = toScala(Accumulator) + def accumulate: AnyAccumulator[A] = toScalaFactory(Accumulator) /** * Copy the elements of this stream into a Scala collection. * - * Converting a parallel streams to an [[Accumulator]] using `stream.toScala(Accumulator)` + * Converting a parallel streams to an [[Accumulator]] using `stream.toScalaFactory(Accumulator)` * builds the result in parallel. * - * A `toScala(Accumulator)` call automatically converts streams of boxed integers, longs or + * A `toScalaFactory(Accumulator)` call automatically converts streams of boxed integers, longs or * doubles are converted to the primitive accumulators ([[IntAccumulator]], etc.). * * When converting a parallel stream to a different Scala collection, the stream is first @@ -230,17 +230,35 @@ trait StreamExtensions { * Sequential streams are directly converted to the target collection. If the target collection * is lazy, the conversion is lazy as well. */ - def toScala[C1](factory: collection.Factory[A, C1])(implicit info: AccumulatorFactoryInfo[A, C1]): C1 = { - + private[java8] def toScalaFactory[C](factory: collection.Factory[A, C])(implicit info: AccumulatorFactoryInfo[A, C]): C = { def anyAcc = stream.collect(AnyAccumulator.supplier[A], AnyAccumulator.adder[A], AnyAccumulator.merger[A]) - if (info.companion == AnyAccumulator) anyAcc.asInstanceOf[C1] - else if (info.companion == IntAccumulator) stream.asInstanceOf[Stream[Int]].collect(IntAccumulator.supplier, IntAccumulator.boxedAdder, IntAccumulator.merger).asInstanceOf[C1] - else if (info.companion == LongAccumulator) stream.asInstanceOf[Stream[Long]].collect(LongAccumulator.supplier, LongAccumulator.boxedAdder, LongAccumulator.merger).asInstanceOf[C1] - else if (info.companion == DoubleAccumulator) stream.asInstanceOf[Stream[Double]].collect(DoubleAccumulator.supplier, DoubleAccumulator.boxedAdder, DoubleAccumulator.merger).asInstanceOf[C1] + if (info.companion == AnyAccumulator) anyAcc.asInstanceOf[C] + else if (info.companion == IntAccumulator) stream.asInstanceOf[Stream[Int]].collect(IntAccumulator.supplier, IntAccumulator.boxedAdder, IntAccumulator.merger).asInstanceOf[C] + else if (info.companion == LongAccumulator) stream.asInstanceOf[Stream[Long]].collect(LongAccumulator.supplier, LongAccumulator.boxedAdder, LongAccumulator.merger).asInstanceOf[C] + else if (info.companion == DoubleAccumulator) stream.asInstanceOf[Stream[Double]].collect(DoubleAccumulator.supplier, DoubleAccumulator.boxedAdder, DoubleAccumulator.merger).asInstanceOf[C] else if (stream.isParallel) anyAcc.to(factory) else factory.fromSpecific(stream.iterator.asScala) } + /** + * Copy the elements of this stream into a Scala collection. + * + * For parallel streams, using [[accumulate]] is recommended as it builds the [[Accumulator]] + * in parallel. + * + * When converting a parallel stream to a different Scala collection, the stream is first + * converted into an [[Accumulator]], which supports parallel building. The accumulator is + * then converted to the target collection. Note that the stream is processed eagerly while + * building the accumulator, even if the target collection is lazy. + * + * Sequential streams are directly converted to the target collection. If the target collection + * is lazy, the conversion is lazy as well. + */ + def toScala[CC[_]](implicit factory: collection.Factory[A, CC[A]]): CC[A] = { + if (stream.isParallel) toScalaFactory(Accumulator).to(factory) + else factory.fromSpecific(stream.iterator.asScala) + } + /** Convert a generic Java Stream wrapping a primitive type to a corresponding primitive * Stream. */ @@ -248,39 +266,39 @@ trait StreamExtensions { } implicit class StreamIntHasAccumulatePrimitive(s: Stream[Int]) { - def accumulatePrimitive: IntAccumulator = s.toScala(Accumulator) + def accumulatePrimitive: IntAccumulator = s.toScalaFactory(Accumulator) } implicit class StreamLongHasAccumulatePrimitive(s: Stream[Long]) { - def accumulatePrimitive: LongAccumulator = s.toScala(Accumulator) + def accumulatePrimitive: LongAccumulator = s.toScalaFactory(Accumulator) } implicit class StreamDoubleHasAccumulatePrimitive(s: Stream[Double]) { - def accumulatePrimitive: DoubleAccumulator = s.toScala(Accumulator) + def accumulatePrimitive: DoubleAccumulator = s.toScalaFactory(Accumulator) } implicit class StreamJIntegerHasAccumulatePrimitive(s: Stream[java.lang.Integer]) { - def accumulatePrimitive: IntAccumulator = s.toScala(Accumulator) + def accumulatePrimitive: IntAccumulator = s.toScalaFactory(Accumulator) } implicit class StreamJLongHasAccumulatePrimitive(s: Stream[java.lang.Long]) { - def accumulatePrimitive: LongAccumulator = s.toScala(Accumulator) + def accumulatePrimitive: LongAccumulator = s.toScalaFactory(Accumulator) } implicit class StreamJDoubleHasAccumulatePrimitive(s: Stream[java.lang.Double]) { - def accumulatePrimitive: DoubleAccumulator = s.toScala(Accumulator) + def accumulatePrimitive: DoubleAccumulator = s.toScalaFactory(Accumulator) } implicit class IntStreamHasToScala(stream: IntStream) { - def accumulate: IntAccumulator = toScala(IntAccumulator) + def accumulate: IntAccumulator = toScalaFactory(IntAccumulator) /** * Copy the elements of this stream into a Scala collection. * - * Converting a parallel streams to an [[Accumulator]] using `stream.toScala(Accumulator)` + * Converting a parallel streams to an [[Accumulator]] using `stream.toScalaFactory(Accumulator)` * builds the result in parallel. * - * A `toScala(Accumulator)` call automatically converts the `IntStream` to a primitive + * A `toScalaFactory(Accumulator)` call automatically converts the `IntStream` to a primitive * [[IntAccumulator]]. * * When converting a parallel stream to a different Scala collection, the stream is first @@ -291,25 +309,44 @@ trait StreamExtensions { * Sequential streams are directly converted to the target collection. If the target collection * is lazy, the conversion is lazy as well. */ - def toScala[C1](factory: collection.Factory[Int, C1])(implicit info: AccumulatorFactoryInfo[Int, C1]): C1 = { + private[java8] def toScalaFactory[C](factory: collection.Factory[Int, C])(implicit info: AccumulatorFactoryInfo[Int, C]): C = { def intAcc = stream.collect(IntAccumulator.supplier, IntAccumulator.adder, IntAccumulator.merger) - if (info.companion == AnyAccumulator) stream.collect(AnyAccumulator.supplier[Int], AnyAccumulator.unboxedIntAdder, AnyAccumulator.merger[Int]).asInstanceOf[C1] - else if (info.companion == IntAccumulator) intAcc.asInstanceOf[C1] + if (info.companion == AnyAccumulator) stream.collect(AnyAccumulator.supplier[Int], AnyAccumulator.unboxedIntAdder, AnyAccumulator.merger[Int]).asInstanceOf[C] + else if (info.companion == IntAccumulator) intAcc.asInstanceOf[C] else if (stream.isParallel) intAcc.to(factory) else factory.fromSpecific(stream.iterator.asInstanceOf[java.util.Iterator[Int]].asScala) } + + /** + * Copy the elements of this stream into a Scala collection. + * + * For parallel streams, using [[accumulate]] is recommended as it builds the [[IntAccumulator]] + * in parallel. + * + * When converting a parallel stream to a different Scala collection, the stream is first + * converted into an [[Accumulator]], which supports parallel building. The accumulator is + * then converted to the target collection. Note that the stream is processed eagerly while + * building the accumulator, even if the target collection is lazy. + * + * Sequential streams are directly converted to the target collection. If the target collection + * is lazy, the conversion is lazy as well. + */ + def toScala[CC[_]](implicit factory: collection.Factory[Int, CC[Int]]): CC[Int] = { + if (stream.isParallel) toScalaFactory(IntAccumulator).to(factory) + else factory.fromSpecific(stream.iterator.asInstanceOf[java.util.Iterator[Int]].asScala) + } } implicit class LongStreamHasToScala(stream: LongStream) { - def accumulate: LongAccumulator = toScala(LongAccumulator) + def accumulate: LongAccumulator = toScalaFactory(LongAccumulator) /** * Copy the elements of this stream into a Scala collection. * - * Converting a parallel streams to an [[Accumulator]] using `stream.toScala(Accumulator)` + * Converting a parallel streams to an [[Accumulator]] using `stream.toScalaFactory(Accumulator)` * builds the result in parallel. * - * A `toScala(Accumulator)` call automatically converts the `LongStream` to a primitive + * A `toScalaFactory(Accumulator)` call automatically converts the `LongStream` to a primitive * [[LongAccumulator]]. * * When converting a parallel stream to a different Scala collection, the stream is first @@ -320,25 +357,44 @@ trait StreamExtensions { * Sequential streams are directly converted to the target collection. If the target collection * is lazy, the conversion is lazy as well. */ - def toScala[C1](factory: collection.Factory[Long, C1])(implicit info: AccumulatorFactoryInfo[Long, C1]): C1 = { + private[java8] def toScalaFactory[C](factory: collection.Factory[Long, C])(implicit info: AccumulatorFactoryInfo[Long, C]): C = { def longAcc = stream.collect(LongAccumulator.supplier, LongAccumulator.adder, LongAccumulator.merger) - if (info.companion == AnyAccumulator) stream.collect(AnyAccumulator.supplier[Long], AnyAccumulator.unboxedLongAdder, AnyAccumulator.merger[Long]).asInstanceOf[C1] - else if (info.companion == LongAccumulator) longAcc.asInstanceOf[C1] + if (info.companion == AnyAccumulator) stream.collect(AnyAccumulator.supplier[Long], AnyAccumulator.unboxedLongAdder, AnyAccumulator.merger[Long]).asInstanceOf[C] + else if (info.companion == LongAccumulator) longAcc.asInstanceOf[C] else if (stream.isParallel) longAcc.to(factory) else factory.fromSpecific(stream.iterator.asInstanceOf[java.util.Iterator[Long]].asScala) } + + /** + * Copy the elements of this stream into a Scala collection. + * + * For parallel streams, using [[accumulate]] is recommended as it builds the [[LongAccumulator]] + * in parallel. + * + * When converting a parallel stream to a different Scala collection, the stream is first + * converted into an [[Accumulator]], which supports parallel building. The accumulator is + * then converted to the target collection. Note that the stream is processed eagerly while + * building the accumulator, even if the target collection is lazy. + * + * Sequential streams are directly converted to the target collection. If the target collection + * is lazy, the conversion is lazy as well. + */ + def toScala[CC[_]](implicit factory: collection.Factory[Long, CC[Long]]): CC[Long] = { + if (stream.isParallel) toScalaFactory(LongAccumulator).to(factory) + else factory.fromSpecific(stream.iterator.asInstanceOf[java.util.Iterator[Long]].asScala) + } } implicit class DoubleStreamHasToScala(stream: DoubleStream) { - def accumulate: DoubleAccumulator = toScala(DoubleAccumulator) + def accumulate: DoubleAccumulator = toScalaFactory(DoubleAccumulator) /** * Copy the elements of this stream into a Scala collection. * - * Converting a parallel streams to an [[Accumulator]] using `stream.toScala(Accumulator)` + * Converting a parallel streams to an [[Accumulator]] using `stream.toScalaFactory(Accumulator)` * builds the result in parallel. * - * A `toScala(Accumulator)` call automatically converts the `DoubleStream` to a primitive + * A `toScalaFactory(Accumulator)` call automatically converts the `DoubleStream` to a primitive * [[DoubleAccumulator]]. * * When converting a parallel stream to a different Scala collection, the stream is first @@ -349,13 +405,32 @@ trait StreamExtensions { * Sequential streams are directly converted to the target collection. If the target collection * is lazy, the conversion is lazy as well. */ - def toScala[C1](factory: collection.Factory[Double, C1])(implicit info: AccumulatorFactoryInfo[Double, C1]): C1 = { + private[java8] def toScalaFactory[C](factory: collection.Factory[Double, C])(implicit info: AccumulatorFactoryInfo[Double, C]): C = { def doubleAcc = stream.collect(DoubleAccumulator.supplier, DoubleAccumulator.adder, DoubleAccumulator.merger) - if (info.companion == AnyAccumulator) stream.collect(AnyAccumulator.supplier[Double], AnyAccumulator.unboxedDoubleAdder, AnyAccumulator.merger[Double]).asInstanceOf[C1] - else if (info.companion == DoubleAccumulator) doubleAcc.asInstanceOf[C1] + if (info.companion == AnyAccumulator) stream.collect(AnyAccumulator.supplier[Double], AnyAccumulator.unboxedDoubleAdder, AnyAccumulator.merger[Double]).asInstanceOf[C] + else if (info.companion == DoubleAccumulator) doubleAcc.asInstanceOf[C] else if (stream.isParallel) doubleAcc.to(factory) else factory.fromSpecific(stream.iterator.asInstanceOf[java.util.Iterator[Double]].asScala) } + + /** + * Copy the elements of this stream into a Scala collection. + * + * For parallel streams, using [[accumulate]] is recommended as it builds the [[DoubleAccumulator]] + * in parallel. + * + * When converting a parallel stream to a different Scala collection, the stream is first + * converted into an [[Accumulator]], which supports parallel building. The accumulator is + * then converted to the target collection. Note that the stream is processed eagerly while + * building the accumulator, even if the target collection is lazy. + * + * Sequential streams are directly converted to the target collection. If the target collection + * is lazy, the conversion is lazy as well. + */ + def toScala[CC[_]](implicit factory: collection.Factory[Double, CC[Double]]): CC[Double] = { + if (stream.isParallel) toScalaFactory(DoubleAccumulator).to(factory) + else factory.fromSpecific(stream.iterator.asInstanceOf[java.util.Iterator[Double]].asScala) + } } } diff --git a/src/test/scala/scala/compat/java8/StreamConvertersTest.scala b/src/test/scala/scala/compat/java8/StreamConvertersTest.scala index f2a084f..0beb9ae 100644 --- a/src/test/scala/scala/compat/java8/StreamConvertersTest.scala +++ b/src/test/scala/scala/compat/java8/StreamConvertersTest.scala @@ -99,18 +99,26 @@ class StreamConvertersTest { val vecO = arrayO(n).toVector assertEq(vecO, newStream(n).toScala(Vector)) assertEq(vecO, newStream(n).parallel.toScala(Vector)) + assertEq(vecO, newStream(n).toScala[Vector]) + assertEq(vecO, newStream(n).parallel.toScala[Vector]) val vecD = arrayD(n).toVector assertEq(vecD, newDoubleStream(n).toScala(Vector)) assertEq(vecD, newDoubleStream(n).parallel.toScala(Vector)) + assertEq(vecD, newDoubleStream(n).toScala[Vector]) + assertEq(vecD, newDoubleStream(n).parallel.toScala[Vector]) val vecI = arrayI(n).toVector assertEq(vecI, newIntStream(n).toScala(Vector)) assertEq(vecI, newIntStream(n).parallel.toScala(Vector)) + assertEq(vecI, newIntStream(n).toScala[Vector]) + assertEq(vecI, newIntStream(n).parallel.toScala[Vector]) val vecL = arrayL(n).toVector assertEq(vecL, newLongStream(n).toScala(Vector)) assertEq(vecL, newLongStream(n).parallel.toScala(Vector)) + assertEq(vecL, newLongStream(n).toScala[Vector]) + assertEq(vecL, newLongStream(n).parallel.toScala[Vector]) } } @@ -150,18 +158,18 @@ class StreamConvertersTest { val vecO = vectO(n) val hsO = hsetO(n) // Seems like a lot of boilerplate, but we need it to test implicit resolution - assertEq(seqO, seqO.seqStream.toScala(Seq)) -// assertEq(seqO, seqO.stepper.parStream.toScala(Seq) // Must go through stepper if we're unsure whether we can parallelize well - assertEq(seqO, arrO.seqStream.toScala(Seq)) - assertEq(seqO, arrO.parStream.toScala(Seq)) - assertEq(seqO, abO.seqStream.toScala(Seq)) - assertEq(seqO, abO.parStream.toScala(Seq)) - assertEq(seqO, wrO.seqStream.toScala(Seq)) - assertEq(seqO, wrO.parStream.toScala(Seq)) - assertEq(seqO, vecO.seqStream.toScala(Seq)) - assertEq(seqO, vecO.parStream.toScala(Seq)) -// assertEq(seqO, hsO.seqStream.toScala(Seq.sortBy(_.toInt)) -// assertEq(seqO, hsO.parStream.toScala(Seq.sortBy(_.toInt)) + assertEq(seqO, seqO.seqStream.toScala[Seq]) +// assertEq(seqO, seqO.stepper.parStream.toScala[Seq]) // Must go through stepper if we're unsure whether we can parallelize well + assertEq(seqO, arrO.seqStream.toScala[Seq]) + assertEq(seqO, arrO.parStream.toScala[Seq]) + assertEq(seqO, abO.seqStream.toScala[Seq]) + assertEq(seqO, abO.parStream.toScala[Seq]) + assertEq(seqO, wrO.seqStream.toScala[Seq]) + assertEq(seqO, wrO.parStream.toScala[Seq]) + assertEq(seqO, vecO.seqStream.toScala[Seq]) + assertEq(seqO, vecO.parStream.toScala[Seq]) +// assertEq(seqO, hsO.seqStream.toScala[Seq].sortBy(_.toInt)) +// assertEq(seqO, hsO.parStream.toScala[Seq].sortBy(_.toInt)) val arrD = arrayD(n) val seqD = arrD.toSeq @@ -169,26 +177,26 @@ class StreamConvertersTest { val wrD = wrapD(n) val vecD = vectD(n) val hsD = hsetD(n) - assertEq(seqD, seqD.seqStream.toScala(Seq)) -// assertEq(seqD, seqD.stepper.parStream.toScala(Seq) - assertEq(seqD, arrD.seqStream.toScala(Seq)) - assertEq(seqD, arrD.parStream.toScala(Seq)) + assertEq(seqD, seqD.seqStream.toScala[Seq]) +// assertEq(seqD, seqD.stepper.parStream.toScala[Seq]) + assertEq(seqD, arrD.seqStream.toScala[Seq]) + assertEq(seqD, arrD.parStream.toScala[Seq]) assert(arrD.seqStream.isInstanceOf[DoubleStream]) assert(arrD.parStream.isInstanceOf[DoubleStream]) - assertEq(seqD, abD.seqStream.toScala(Seq)) - assertEq(seqD, abD.parStream.toScala(Seq)) + assertEq(seqD, abD.seqStream.toScala[Seq]) + assertEq(seqD, abD.parStream.toScala[Seq]) assert(abD.seqStream.isInstanceOf[DoubleStream]) assert(abD.parStream.isInstanceOf[DoubleStream]) - assertEq(seqD, wrD.seqStream.toScala(Seq)) - assertEq(seqD, wrD.parStream.toScala(Seq)) + assertEq(seqD, wrD.seqStream.toScala[Seq]) + assertEq(seqD, wrD.parStream.toScala[Seq]) assert(wrD.seqStream.isInstanceOf[DoubleStream]) assert(wrD.parStream.isInstanceOf[DoubleStream]) - assertEq(seqD, vecD.seqStream.toScala(Seq)) - assertEq(seqD, vecD.parStream.toScala(Seq)) + assertEq(seqD, vecD.seqStream.toScala[Seq]) + assertEq(seqD, vecD.parStream.toScala[Seq]) assert(vecD.seqStream.isInstanceOf[DoubleStream]) assert(vecD.parStream.isInstanceOf[DoubleStream]) -// assertEq(seqD, hsD.seqStream.toScala(Seq.sorted) -// assertEq(seqD, hsD.parStream.toScala(Seq.sorted) +// assertEq(seqD, hsD.seqStream.toScala[Seq].sorted) +// assertEq(seqD, hsD.parStream.toScala[Seq].sorted) // assert(hsD.seqStream.isInstanceOf[DoubleStream]) // assert(hsD.parStream.isInstanceOf[DoubleStream]) @@ -198,26 +206,26 @@ class StreamConvertersTest { val wrI = wrapI(n) val vecI = vectI(n) val hsI = hsetI(n) - assertEq(seqI, seqI.seqStream.toScala(Seq)) -// assertEq(seqI, seqI.stepper.parStream.toScala(Seq) - assertEq(seqI, arrI.seqStream.toScala(Seq)) - assertEq(seqI, arrI.parStream.toScala(Seq)) + assertEq(seqI, seqI.seqStream.toScala[Seq]) +// assertEq(seqI, seqI.stepper.parStream.toScala[Seq]) + assertEq(seqI, arrI.seqStream.toScala[Seq]) + assertEq(seqI, arrI.parStream.toScala[Seq]) assert(arrI.seqStream.isInstanceOf[IntStream]) assert(arrI.parStream.isInstanceOf[IntStream]) - assertEq(seqI, abI.seqStream.toScala(Seq)) - assertEq(seqI, abI.parStream.toScala(Seq)) + assertEq(seqI, abI.seqStream.toScala[Seq]) + assertEq(seqI, abI.parStream.toScala[Seq]) assert(abI.seqStream.isInstanceOf[IntStream]) assert(abI.parStream.isInstanceOf[IntStream]) - assertEq(seqI, wrI.seqStream.toScala(Seq)) - assertEq(seqI, wrI.parStream.toScala(Seq)) + assertEq(seqI, wrI.seqStream.toScala[Seq]) + assertEq(seqI, wrI.parStream.toScala[Seq]) assert(wrI.seqStream.isInstanceOf[IntStream]) assert(wrI.parStream.isInstanceOf[IntStream]) - assertEq(seqI, vecI.seqStream.toScala(Seq)) - assertEq(seqI, vecI.parStream.toScala(Seq)) + assertEq(seqI, vecI.seqStream.toScala[Seq]) + assertEq(seqI, vecI.parStream.toScala[Seq]) assert(vecI.seqStream.isInstanceOf[IntStream]) assert(vecI.parStream.isInstanceOf[IntStream]) -// assertEq(seqI, hsI.seqStream.toScala(Seq.sorted) -// assertEq(seqI, hsI.parStream.toScala(Seq.sorted) +// assertEq(seqI, hsI.seqStream.toScala[Seq].sorted) +// assertEq(seqI, hsI.parStream.toScala[Seq].sorted) // assert(hsI.seqStream.isInstanceOf[IntStream]) // assert(hsI.parStream.isInstanceOf[IntStream]) @@ -227,26 +235,26 @@ class StreamConvertersTest { val wrL = wrapL(n) val vecL = vectL(n) val hsL = hsetL(n) - assertEq(seqL, seqL.seqStream.toScala(Seq)) -// assertEq(seqL, seqL.stepper.parStream.toScala(Seq) - assertEq(seqL, arrL.seqStream.toScala(Seq)) - assertEq(seqL, arrL.parStream.toScala(Seq)) + assertEq(seqL, seqL.seqStream.toScala[Seq]) +// assertEq(seqL, seqL.stepper.parStream.toScala[Seq]) + assertEq(seqL, arrL.seqStream.toScala[Seq]) + assertEq(seqL, arrL.parStream.toScala[Seq]) assert(arrL.seqStream.isInstanceOf[LongStream]) assert(arrL.parStream.isInstanceOf[LongStream]) - assertEq(seqL, abL.seqStream.toScala(Seq)) - assertEq(seqL, abL.parStream.toScala(Seq)) + assertEq(seqL, abL.seqStream.toScala[Seq]) + assertEq(seqL, abL.parStream.toScala[Seq]) assert(abL.seqStream.isInstanceOf[LongStream]) assert(abL.parStream.isInstanceOf[LongStream]) - assertEq(seqD, wrD.seqStream.toScala(Seq)) - assertEq(seqD, wrD.parStream.toScala(Seq)) + assertEq(seqD, wrD.seqStream.toScala[Seq]) + assertEq(seqD, wrD.parStream.toScala[Seq]) assert(wrL.seqStream.isInstanceOf[LongStream]) assert(wrL.parStream.isInstanceOf[LongStream]) - assertEq(seqD, wrD.seqStream.toScala(Seq)) - assertEq(seqD, wrD.parStream.toScala(Seq)) + assertEq(seqD, wrD.seqStream.toScala[Seq]) + assertEq(seqD, wrD.parStream.toScala[Seq]) assert(vecL.seqStream.isInstanceOf[LongStream]) assert(vecL.parStream.isInstanceOf[LongStream]) -// assertEq(seqL, hsL.seqStream.toScala(Seq.sorted) -// assertEq(seqL, hsL.parStream.toScala(Seq.sorted) +// assertEq(seqL, hsL.seqStream.toScala[Seq].sorted) +// assertEq(seqL, hsL.parStream.toScala[Seq].sorted) // assert(hsL.seqStream.isInstanceOf[LongStream]) // assert(hsL.parStream.isInstanceOf[LongStream]) } @@ -255,14 +263,14 @@ class StreamConvertersTest { @Test def primitiveStreamTypes(): Unit = { // Unboxed native + widening Steppers available: - assertEquals(Vector[Int](1, 2, 3), (Array[Int](1, 2, 3).seqStream: IntStream).toScala(Vector)) - assertEquals(Vector[Short](1.toShort, 2.toShort, 3.toShort), (Array[Short](1.toShort, 2.toShort, 3.toShort).seqStream: IntStream).toScala(Vector)) - assertEquals(Vector[String]("a", "b"), (Array[String]("a", "b").seqStream: Stream[String]).toScala(Vector)) + assertEquals(Vector[Int](1, 2, 3), (Array[Int](1, 2, 3).seqStream: IntStream).toScala[Vector]) + assertEquals(Vector[Short](1.toShort, 2.toShort, 3.toShort), (Array[Short](1.toShort, 2.toShort, 3.toShort).seqStream: IntStream).toScala[Vector]) + assertEquals(Vector[String]("a", "b"), (Array[String]("a", "b").seqStream: Stream[String]).toScala[Vector]) // Boxed collections, widening via boxed AnySteppers: - assertEquals(Vector[Int](1, 2, 3), (Vector[Int](1, 2, 3).seqStream: IntStream).toScala(Vector)) - assertEquals(Vector[Short](1.toShort, 2.toShort, 3.toShort), (Vector[Short](1.toShort, 2.toShort, 3.toShort).seqStream: IntStream).toScala(Vector)) - assertEquals(Vector[String]("a", "b"), (Vector[String]("a", "b").seqStream: Stream[String]).toScala(Vector)) + assertEquals(Vector[Int](1, 2, 3), (Vector[Int](1, 2, 3).seqStream: IntStream).toScala[Vector]) + assertEquals(Vector[Short](1.toShort, 2.toShort, 3.toShort), (Vector[Short](1.toShort, 2.toShort, 3.toShort).seqStream: IntStream).toScala[Vector]) + assertEquals(Vector[String]("a", "b"), (Vector[String]("a", "b").seqStream: Stream[String]).toScala[Vector]) } @Test