scala/scala/graphs/contributors?from=2014-11-01&to=2017-10-19&type=c
jar | 2.11.11 | 2.12.4 |
---|---|---|
scala-compiler | 15M | 9.3M |
scala-library | 5.5M | 5.0M |
scala-reflect | 4.4M | 3.4M |
-Dscala.color
Either
is now right-biasedwithFilter
for for
sbt new
def map[R](mapper: T => R): Stream[R]
<R> Stream<R> map(Function<? super T, ? extends R> mapper)
trait
compiles to Java 8 interface
FunctionN
compiles to SAM type (Java 8 λ)trait extends class
super
call ⟹ accessorscala> import java.util.{Arrays, List, ArrayList}
scala> import java.util.stream.{Stream, IntStream}
scala> val myList = Arrays.asList("a1", "a2", "b1", "c2", "c1")
scala> myList.stream.filter(s => s.startsWith("c")).
map(_.toUpperCase).
sorted.
forEach(println)
scala> Arrays.asList("a1", "a2", "a3").stream.
findFirst.
ifPresent(println)
scala> Stream.of("a1", "a2", "a3").
findFirst.
ifPresent(println)
scala> IntStream.range(1, 4).forEach(println)
scala> Arrays.stream(Array(1, 2, 3)).
map(n => 2 * n + 1).average.
ifPresent(println)
scala> Stream.of("a1", "a2", "a3").
map(_.substring(1)).
mapToInt(Integer.parseInt).max.ifPresent(println)
<console>:14: error: type mismatch;
found : (x$1: String)Int <and> (x$1: String, x$2: Int)Int
required: java.util.function.ToIntFunction[? >: ?0]
Stream.of("a1", "a2", "a3").map(_.substring(1)).mapToInt(Integer.parseInt).max.ifPresent(println)
^
scala> Stream.of("a1", "a2", "a3").
map[String](_.substring(1)).
mapToInt(Integer.parseInt).max.ifPresent(println)
3
class C[V] {
def sort(cmp: (V, V) => Int): C[V] = ???
def sort(cmp: java.util.Comparator[V]): C[V] = ???
}
val c: C[Int] = ???
c sort (_ - _) // types inferred in 2.12
c sort ((a: Int, b: Int) => a - b)
c sort ((_ - _): java.util.Comparator[Int])
The Comparator
overload is applicable to:
Comparator
The Function2
overload is applicable to:
Comparator
// old:
def map[B, That](f: A => B)(
implicit bf: CanBuildFrom[Repr, B, That]): That
// new:
def map[B](f: A => B): C[B] // intent much clearer
// old:
def to[Col[_]](
implicit cbf: CanBuildFrom[Nothing, A, Col[A @uV]]): Col[A @uV]
// new:
def to(bf: BuildFrom[Iterable[A], A]): bf.To
// old call site:
coll.to[Set]
// new call site:
coll.to(Set)
coll.to(BitSet) // not possible before
coll.to(Map) // not possible before