List ProductByFoldRight

摘要: object ProductFolderRight { def product(ld: List[Double]): Double = { def loop(ls: List[Double], acc: Double): Double = ls match { case Nil => acc case 0.0 :: t => 0... 阅读全文
posted @ 2016-04-19 21:21 JonkeyGuan 阅读(76) 评论(0) 推荐(0) 编辑

List Init

摘要: object Init { def init[A](l: List[A]): List[A] = { def loop[A](l1: List[A], i: Int): List[A] = { if (l1.length == 0 || l1.length <= i) Nil else if (l1.length == 1) l1 else lo... 阅读全文
posted @ 2016-04-18 23:18 JonkeyGuan 阅读(317) 评论(0) 推荐(0) 编辑

List Drop

摘要: object Drop { def drop[A](l: List[A], n: Int): List[A] = { if (n = l.length) Nil else drop(l.tail, n - 1) } def main(args: Array[String]): Unit = { println(drop(List(1, 2, 3, 4, 5... 阅读全文
posted @ 2016-04-18 23:17 JonkeyGuan 阅读(352) 评论(0) 推荐(0) 编辑

List DropWhile

摘要: 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... 阅读全文
posted @ 2016-04-18 23:17 JonkeyGuan 阅读(277) 评论(0) 推荐(0) 编辑

List SetHead

摘要: 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... 阅读全文
posted @ 2016-04-18 23:16 JonkeyGuan 阅读(225) 评论(0) 推荐(0) 编辑

List Tail

摘要: 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... 阅读全文
posted @ 2016-04-18 23:16 JonkeyGuan 阅读(322) 评论(0) 推荐(0) 编辑

List PatternMatching

摘要: 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... 阅读全文
posted @ 2016-04-18 23:15 JonkeyGuan 阅读(212) 评论(0) 推荐(0) 编辑

List Compose

摘要: object Compose { def compose[A, B, C](f: B => C, g: A => B): A => C = { (a: A) => f(g(a)) } def main(args: Array[String]): Unit = { def int2String(a: Int): String = a.toString def... 阅读全文
posted @ 2016-04-17 21:50 JonkeyGuan 阅读(207) 评论(0) 推荐(0) 编辑

List Uncurry

摘要: 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... 阅读全文
posted @ 2016-04-17 21:49 JonkeyGuan 阅读(111) 评论(0) 推荐(0) 编辑

List Curry

摘要: 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... 阅读全文
posted @ 2016-04-17 21:48 JonkeyGuan 阅读(117) 评论(0) 推荐(0) 编辑

List Polymorphic

摘要: object Polymorphic { def isSorted[A](as: Array[A], ordered: (A, A) => Boolean): Boolean = { @annotation.tailrec def loop(n: Int): Boolean = { if (as.length = as.length - 1) true ... 阅读全文
posted @ 2016-04-17 17:35 JonkeyGuan 阅读(94) 评论(0) 推荐(0) 编辑

List Fibonacci

摘要: Thinking approach 阅读全文
posted @ 2016-04-17 17:16 JonkeyGuan 阅读(135) 评论(0) 推荐(0) 编辑