extend Stream
convert a scala.Function2
to a java.util.function.BinaryOperator
convert a scala.Function2
to a java.util.function.BinaryOperator
without the import:
scala> java.util.stream.Stream.of(1, 2, 3, 4).reduce(0, (_: Int) + (_: Int)) <console>:12: error: overloaded method value reduce with alternatives: [U](x$1: U, x$2: java.util.function.BiFunction[U, _ >: Int, U], x$3: java.util.function.BinaryOperator[U])U <and> (x$1: java.util.function.BinaryOperator[Int])java.util.Optional[Int] <and> (x$1: Int,x$2: java.util.function.BinaryOperator[Int])Int cannot be applied to (Int, (Int, Int) => Int) java.util.stream.Stream.of(1, 2, 3, 4).reduce(0, (_: Int) + (_: Int))
with the import:
scala> import sclib.ops.java8._ scala> java.util.stream.Stream.of(1, 2, 3, 4).reduce(0, (_: Int) + (_: Int)) res1: Int = 10
convert a scala.Function1
to a java.util.function.Consumer
convert a scala.Function1
to a java.util.function.Consumer
without the import:
scala> java.util.stream.Stream.of(1, 2, 3, 4).forEach(println(_: Int)) <console>:12: error: type mismatch; found : Int => Unit required: java.util.function.Consumer[_ >: Int] java.util.stream.Stream.of(1, 2, 3, 4).forEach(println(_: Int))
with the import:
scala> import sclib.ops.java8._ scala> java.util.stream.Stream.of(1, 2, 3, 4).forEach(println(_: Int)) 1 2 3 4
convert a scala.Function1
to a java.util.function.Function
convert a scala.Function1
to a java.util.function.Function
without the import:
scala> java.util.stream.Stream.of(1, 2, 3,4).map((_: Int) * 10).toArray <console>:12: error: type mismatch; found : Int => Int required: java.util.function.Function[_ >: Int, _] java.util.stream.Stream.of(1, 2, 3,4).map((_: Int) * 10).toArray
with the import:
scala> import sclib.ops.java8._ scala> java.util.stream.Stream.of(1, 2, 3,4).map((_: Int) * 10).toArray res1: Array[Object] = Array(10, 20, 30, 40)
convert a scala.Function1
to a java.util.function.Predicate
convert a scala.Function1
to a java.util.function.Predicate
without the import:
scala> java.util.stream.Stream.of(1, 2, 3, 4).filter((_: Int) < 3).toArray <console>:12: error: type mismatch; found : Int => Boolean required: java.util.function.Predicate[_ >: Int] java.util.stream.Stream.of(1, 2, 3, 4).filter((_: Int) < 3).toArray
with the import:
scala> import sclib.ops.java8._ scala> java.util.stream.Stream.of(1, 2, 3, 4).filter((_: Int) < 3).toArray res1: Array[Object] = Array(1, 2)
java8 interoperability
check the member documentation for examples