List Add1

object Add1 {

  def add1(l: List[Int]): List[Int] = FoldRight.foldRight(l, Nil: List[Int])((a: Int, b: List[Int]) => a + 1 :: b)

  def main(args: Array[String]): Unit = {

    println(add1(List(1, 2, 3, 4, 5, 6, 7)))

  }

}
List(2, 3, 4, 5, 6, 7, 8)
原文地址:https://www.cnblogs.com/JonkeyGuan/p/5423763.html