This file contains hidden or 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
| <?xml version="1.0" encoding="UTF-8"?> | |
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
| <modelVersion>4.0.0</modelVersion> | |
| <groupId>org.scala-tools.maven-scala-plugin</groupId> | |
| <artifactId>testJavaAndScala</artifactId> | |
| <version>1.0-SNAPSHOT</version> | |
| <name>Test for Java + Scala compilation</name> |
This file contains hidden or 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
| Welcome to Scala version 2.8.0.r0-b20090301210344 (Java HotSpot(TM) Client VM, Java 1.6.0_10). | |
| Type in expressions to have them evaluated. | |
| Type :help for more information. | |
| scala> trait ReponseHelper[A]; | |
| defined trait ReponseHelper ^ | |
| scala> def doSomething[A](x : ReponseHelper[_ <: A]) : A = null.asInstanceOf[A] | |
| doSomething: [A](ReponseHelper[_ <: A])A ^ | |
This file contains hidden or 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
| josh@suereth-desktop:~/projects/blog/s99$ scala | |
| Welcome to Scala version 2.7.1.final (OpenJDK Client VM, Java 1.6.0_0). | |
| Type in expressions to have them evaluated. | |
| Type :help for more information. | |
| scala> def x(one:Int, two:Int, three:Int, four:Int, five:Int, six:Int, seven:int, eight:int, nine:Int, ten:Int, eleven:Int, twelve:Int, thirteen:Int, fourteen:Int, fifteen:Int, sixteen:Int, seventeen:Int, eighteen:Int, nineteen:Int, twenty:Int, twentyone:Int, twentytwo:Int, twentythree:Int) = one + two | |
| x: (Int,Int,Int,Int,Int,Int,int,int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int,Int)Int | |
| scala> x _ | |
| <console>:6: error: missing arguments for method x in object $iw; |
This file contains hidden or 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
| Welcome to Scala version 2.8.0.r21454-b20100411185142 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_15). | |
| Type in expressions to have them evaluated. | |
| Type :help for more information. | |
| scala> val x : Int => Unit = y => println(y) | |
| x: (Int) => Unit = <function1> | |
| scala> x(v1 = 2) | |
| 2 |
This file contains hidden or 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> class Foo { | |
| | type T = this.type | |
| | def cloneit : T = { | |
| | val x = new Foo | |
| | x match { | |
| | case y : T => y | |
| | case _ => error("ZOMG") | |
| | } | |
| | } | |
| | } |
This file contains hidden or 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
| Index: src/library/scala/collection/TraversableLike.scala | |
| =================================================================== | |
| --- src/library/scala/collection/TraversableLike.scala (revision 22850) | |
| +++ src/library/scala/collection/TraversableLike.scala (working copy) | |
| @@ -313,6 +313,19 @@ | |
| for (x <- this) (if (p(x)) l else r) += x | |
| (l.result, r.result) | |
| } | |
| + /** Partitions this $coll in two ${colls} according to the | |
| + * transformation to an Either. |
This file contains hidden or 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> def data(block : Int => Unit) { for(i <- 0 to 10) block(i) } | |
| data: (block: (Int) => Unit)Unit | |
| scala> val x = new Traversable[Int] { | |
| | def foreach[U](f : Int => U) = { | |
| | data( f(_) : Unit) | |
| | } | |
| | } | |
| x: java.lang.Object with Traversable[Int] = line15(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) |
This file contains hidden or 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
| import collection.generic.CanBuildFrom | |
| import util.continuations._ | |
| class SuspendableProxy[+T, +Repr <: Iterable[T]](xs: Repr)(implicit cbf : CanBuildFrom[Repr, T, Repr]) { | |
| private[this] def newBuilder = cbf() | |
| def foreach[A](body: T => Unit @cps[A]): Unit @cps[A] = { | |
| val it = xs.iterator | |
| while (it.hasNext) { | |
| body(it.next) |
This file contains hidden or 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> def replace(what: String)(rules: List[(String,String)]): String = | |
| | rules.foldLeft(what)((seed,tuple) => | |
| | seed.replaceAll(tuple._1,tuple._2)) | |
| replace: (what: String)(rules: List[(String, String)])String | |
| scala> replace("Little Bunny Foo foo")(List("Foo" -> "Pancake", "Bunny" -> "Rabbit")) | |
| res3: String = Little Rabbit Pancake foo | |
| scala> def recurse(times: Int)(what: => String): String = { |
This file contains hidden or 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> def recurse(times: Int)(what : String)(how: String => String): String = { | |
| | def rpt(times: Int, previous: => String): String = { | |
| | println("Agg: " + previous) | |
| | times match { | |
| | case 0 => println("Done"); previous | |
| | case _ => println("Recursing"); rpt(times - 1, how(previous)) | |
| | } | |
| | } | |
| | rpt(times, what) | |
| | } |
OlderNewer