Skip to content

Instantly share code, notes, and snippets.

<?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>
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 ^
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;
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
scala> class Foo {
| type T = this.type
| def cloneit : T = {
| val x = new Foo
| x match {
| case y : T => y
| case _ => error("ZOMG")
| }
| }
| }
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.
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)
@jsuereth
jsuereth / SuspendableProxy.scala
Created February 21, 2011 22:11
First cut at attempting to support CPS plugin and collections.
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)
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 = {
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)
| }