scala/lib.scala
changeset 193 317a2532c567
child 221 18905d086cbb
equal deleted inserted replaced
192:3c1107984b41 193:317a2532c567
       
     1 package object lib {
       
     2 
       
     3 //some list functions
       
     4 def tl[A](xs: List[A]) : List[A] = xs match {
       
     5   case Nil => Nil
       
     6   case x::xs => xs
       
     7 }
       
     8 
       
     9 def hd[A](xs: List[A]) : A = xs.head
       
    10 
       
    11 def nth_of[A](xs: List[A], n: Int) = 
       
    12   if (n <= xs.length) Some(xs(n)) else None 
       
    13 
       
    14 //some map functions
       
    15 def dget(m: Map[Int, Int], n: Int) = m.getOrElse(n, 0)
       
    16 
       
    17 //some string functions
       
    18 def join[A](xs: List[A]) = xs.foldLeft("")(_.toString + _)
       
    19 
       
    20 }