scala/lib.scala
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Fri, 01 Mar 2013 11:16:30 +0000
changeset 206 17d80924af53
parent 193 317a2532c567
child 221 18905d086cbb
permissions -rw-r--r--
added a test to make the simplifier be fast enough to do actual compilations

package object lib {

//some list functions
def tl[A](xs: List[A]) : List[A] = xs match {
  case Nil => Nil
  case x::xs => xs
}

def hd[A](xs: List[A]) : A = xs.head

def nth_of[A](xs: List[A], n: Int) = 
  if (n <= xs.length) Some(xs(n)) else None 

//some map functions
def dget(m: Map[Int, Int], n: Int) = m.getOrElse(n, 0)

//some string functions
def join[A](xs: List[A]) = xs.foldLeft("")(_.toString + _)

}