首页 > 其他 > 详细

DropWhile

时间:2016-04-18 23:58:40      阅读:439      评论:0      收藏:0      [点我收藏+]
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[String]): Unit = {
    println(dropWhile(Nil, (a: Int) => a < 0))
    println(dropWhile(List(-1, -3, -2, 3, 4, 5, 6), (a: Int) => a < 0))
  }
}

 

List()
List(3, 4, 5, 6)

 

DropWhile

原文:http://www.cnblogs.com/JonkeyGuan/p/5406376.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!