[豆知识] Scala 2.8各种hello world

RednaxelaFX 2010-05-09
Welcome to Scala version 2.8.0.RC1 (Java HotSpot(TM) Client VM, Java 1.6.0_18).
Type in expressions to have them evaluated.
Type :help for more information.

scala> Map("A" -> 1, "B" -> 2)
res0: scala.collection.immutable.Map[java.lang.String,Int] = Map((A,1), (B,2))

scala> Map("A" -> 1, "B" -> 2) map(e => e._1)
res1: scala.collection.immutable.Iterable[java.lang.String] = List(A, B)

scala> Map("A" -> 1, "B" -> 2) map(e => (e._2, e._1))
res2: scala.collection.immutable.Map[Int,java.lang.String] = Map((1,A), (2,B))

scala> Map("A" -> 1, "B" -> 1) map(e => (e._2, e._1))
res3: scala.collection.immutable.Map[Int,java.lang.String] = Map((1,B))

有趣……
dogstar 2010-05-10
RednaxelaFX 写道
Welcome to Scala version 2.8.0.RC1 (Java HotSpot(TM) Client VM, Java 1.6.0_18).
Type in expressions to have them evaluated.
Type :help for more information.

scala> Map("A" -> 1, "B" -> 2)
res0: scala.collection.immutable.Map[java.lang.String,Int] = Map((A,1), (B,2))

scala> Map("A" -> 1, "B" -> 2) map(e => e._1)
res1: scala.collection.immutable.Iterable[java.lang.String] = List(A, B)

scala> Map("A" -> 1, "B" -> 2) map(e => (e._2, e._1))
res2: scala.collection.immutable.Map[Int,java.lang.String] = Map((1,A), (2,B))

scala> Map("A" -> 1, "B" -> 1) map(e => (e._2, e._1))
res3: scala.collection.immutable.Map[Int,java.lang.String] = Map((1,B))

有趣……



怎么,怎么了?
RednaxelaFX 2010-05-10
dogstar 写道
怎么,怎么了?

没啊,2.8新增的CanBuildFrom系的函数非常搞鬼,可以根据传进来的参数的类型来弄出不同的行为。上面代码一个返回List一个返回Map诶
dogstar 2010-05-11
前几天看scala 2010days的ppt,这帮人又在折腾什么paiallel collections, java的collections 转换到自己的collection这块做的咋样了,说说
Global site tag (gtag.js) - Google Analytics