摘要:
object DropWhile { def dropWhile[A](l: List[A], f: A => Boolean): List[A] = l match { case Nil => Nil case h :: t => if (f(h)) dropWhile(t, f) else h :: t } def main(args: Array[St... 阅读全文
摘要:
object SetHead { def setHead[T](ls: List[T], head: T): List[T] = ls match { case Nil => Nil case h :: t => head :: t } def main(args: Array[String]): Unit = { println(setHead(N... 阅读全文
摘要:
object Tail { def tail[T](ls: List[T]): List[T] = ls match { case Nil => Nil case h :: Nil => Nil case _ :: t => t } def main(args: Array[String]): Unit = { println(tai... 阅读全文
摘要:
object PatternMatching { def main(args: Array[String]): Unit = { val x = List(1, 2, 3, 4, 5) match { case ::(x, ::(2, ::(4, _))) => x case Nil => 42... 阅读全文
摘要:
object Uncurry { def uncurry[A,B,C](f: A => B => C): (A, B) => C = { (a: A, b: B) => f(a)(b) } def main(args: Array[String]): Unit = { def add(a: Int, b: Int): Int = a + b def... 阅读全文
摘要:
object Curry { def curry[A, B, C](f: (A, B) => C): A => (B => C) = { (a: A) => (b: B) => f(a, b) } def main(args: Array[String]): Unit = { def add(a: Int, b: Int): Int = a + b def... 阅读全文