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)

 

posted on 2016-04-23 08:22  JonkeyGuan  阅读(177)  评论(0编辑  收藏  举报