标签:
object FoldRight { def foldRight[A, B](as: List[A], z: B)(f: (A, B) => B): B = as match { case Nil => z case ::(x, xs) => f(x, foldRight(xs, z)(f)) } def main(args: Array[String]): Unit = { println(foldRight(List(1, 2, 3), Nil: List[Int])(::(_, _))) } }
List(1, 2, 3)
标签:
原文地址:http://www.cnblogs.com/JonkeyGuan/p/5410214.html