Permalink
Browse files

added run comments, checked for compilability and fixed some compile …

…bugs.
  • Loading branch information...
1 parent b026dbd commit 38194375324228b11e81dafea5914d2fa2761e52 Lutz Hankewitz committed Jan 20, 2012
@@ -1,4 +1,7 @@
+// Start scala and run via> :load CustomCollections.scala
+
import java.util.{Collection => JCollection, ArrayList }
+
class JavaToTraversable[E](javaCollection: JCollection[E]) extends Traversable[E] {
def foreach[U](f : E => U): Unit = {
@@ -12,6 +15,6 @@ class JavaToTraversable[E](javaCollection: JCollection[E]) extends Traversable[E
// val jCol1 = new ArrayList[Int]
// jCol1.add(100)
-//
+
// val t = new JavaToTraversable(jCol1)
// println(t map { _ + 1 })
View
@@ -1,3 +1,11 @@
+// check in windows with >netstat -a
+// or in Unix with >lsof | grep TCP
+// the used ports on your machine and enter one of them as port(val port = ...)
+// Start scala und load EitherExample.scala >:load EitherExample.scala
+
+
+val port = 5354
+
def throwableToLeft[T](block: => T): Either[java.lang.Throwable, T] =
try {
Right(block)
@@ -7,7 +15,7 @@ def throwableToLeft[T](block: => T): Either[java.lang.Throwable, T] =
import java.net._
-throwableToLeft { new Socket("localhost", 4444) } match {
+throwableToLeft { new Socket("localhost", port) } match {
case Right(s) => println(s)
case Left(t) => t.printStackTrace
}
@@ -1,3 +1,5 @@
+// Start scala >scala
+// load into the REPL> :load FilterAndWithFilterExample.scala
val list = List(1, 2, 3)
var go = true
@@ -1,3 +1,6 @@
+// Start scala >scala
+// load into the REPL> :load ForComprehension.scala
+
case class Artist(name: String, genre: String)
val artists = List(Artist("Pink Floyd", "Rock"),
@@ -1,3 +1,6 @@
+// Start scala >scala
+// load into the REPL> :load FunctionalObjects.scala
+
object foldl {
def apply[A, B](xs: Traversable[A], defaultValue: B)(op: (B, A) => B) = (defaultValue /: xs)(op)
View
@@ -1,3 +1,8 @@
+// Start scala >scala
+// load Maybe.scala in the REPL first> :load Maybe.scala
+// load into the REPL> :load GetPosition.scala
+
+
def position[A](xs: List[A], value: A): Maybe[Int] = {
val index = xs.indexOf(value)
if(index != -1) Just(index) else Nil
@@ -1,11 +1,14 @@
+// Start scala >scala
+// load into the REPL> :load HigherOrderFunctions.scala
+
def addOne(num: Int) = {
def ++ = (x:Int) => x + 1
++(num)
}
def map[A, B](xs: List[A], f: A => B): List[B] = {
xs match {
- case List() => Nil
+ case List() => List[B]()
case head :: tail => f(head) :: map(tail, f)
}
}
@@ -20,7 +23,7 @@ def map2[A, B](xs: List[A])(f: A => B): List[B] = {
def flatten[B](xss: List[List[B]]): List[B] = {
xss match {
- case List() => Nil
+ case List() => List[B]()
case head :: tail => head ::: flatten(tail)
}
}
View
@@ -1,3 +1,6 @@
+// Start scala >scala
+// load into the REPL> :load Infinite.scala
+
def fib(n: Int): Int = n match {
case 0 => 0
case 1 => 1
@@ -1,3 +1,5 @@
+// Start scala >scala
+// load into the REPL> :load InsertionSort.scala
import collection.mutable.ArrayBuffer
View
@@ -1,3 +1,6 @@
+// Start scala >scala
+// load into the REPL> :load Maybe.scala
+
sealed abstract class Maybe[+A] {
def isEmpty: Boolean
def get: A
View
@@ -1,10 +1,13 @@
+// Start scala >scala
+// load into the REPL> :load ViewExample.scala
+
import scala.io._
import scala.xml.XML
def tweets(handle: String) = {
println("processing tweets for " + handle)
val source = Source.fromURL(new java.net.URL("http://search.twitter.com/search.atom?q=" + handle))
- val iterator = source.getLines(System.getProperty("line.separator"))
+ val iterator = source.getLines()
val builder = new StringBuilder
for(line <- iterator) builder.append(line)
XML.loadString(builder.toString)

1 comment on commit 3819437

Owner

lhankewitz commented on 3819437 Jan 20, 2012

getLines no longer accepts a parameter.

Please sign in to comment.