Created
October 29, 2010 06:06
-
-
Save ymnk/653010 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ scala | |
Welcome to Scala version 2.8.0.final (Java HotSpot(TM) Client VM, Java 1.6.0_16). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> "IBM".map(_-1) | |
res0: scala.collection.immutable.IndexedSeq[Int] = Vector(72, 65, 76) | |
scala> "IBM".map(_-1):String | |
<console>:6: error: type mismatch; | |
found : scala.collection.immutable.IndexedSeq[Int] | |
required: String | |
"IBM".map(_-1):String | |
scala> "IBM".map(_-1)(collection.breakOut):String | |
<console>:6: error: type mismatch; | |
found : java.lang.Object with scala.collection.generic.CanBuildFrom[Any,Char,String] | |
required: scala.collection.generic.CanBuildFrom[String,Int,String] | |
"IBM".map(_-1)(collection.breakOut):String | |
scala> Vector(73, 66, 77).map(_-1)(collection.breakOut):String | |
<console>:6: error: type mismatch; | |
found : java.lang.Object with scala.collection.generic.CanBuildFrom[Any,Char,String] | |
required: scala.collection.generic.CanBuildFrom[scala.collection.immutable.Vector[Int],I\ | |
nt,String] | |
Vector(73, 66, 77).map(_-1)(collection.breakOut):String ^ | |
scala> :load Test.scala | |
:load Test.scala | |
Loading Test.scala... | |
defined module Test | |
scala> import Test._ | |
import Test._ | |
scala> "IBM".map(_-1):String | |
res2: String = HAL | |
scala> Vector(73, 66, 77).map(_-1) | |
res3: scala.collection.immutable.Vector[Int] = Vector(72, 65, 76) | |
scala> Vector(73, 66, 77).map(_-1)(collection.breakOut):String | |
res5: String = HAL | |
scala> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Test { | |
implicit def foo = new collection.generic.CanBuildFrom[String, Int, String]{ | |
import collection.mutable.{Builder, StringBuilder} | |
def apply(from: String) = apply() | |
def apply() = new Builder[Int, String]{ | |
val s = new StringBuilder | |
def +=(elem: Int) = { s+=(elem.toChar); this } | |
def clear() = s.clear() | |
def result(): String = s.result() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment