原创文章,转载请注明出处!

原文地址: http://www.ptbird.cn/2016/07/19/scala-chuji-demo-35

There I am,in the world more exciting!

by postbird

www.ptbird.cn



package com.ptbird.scala /** * Created by postbird on 2016/5/26. */ object FoldTest { def main(args: Array[String]): Unit = { println((1 to 100 ).foldLeft(0)(_+_)) //5050 println((0/:(1 to 100))(_+_)) //5050 println((1 to 2 ).foldRight(100)(_-_)) //99 // 2-100=-98 1-(-98)=99 println(((1 to 100):\0)(_+_)) //5050 println(List(1,-3,4,2,6) sortWith(_<_)) println(List(1,-3,4,2,6) sortWith((_>_))) // List(-3, 1, 2, 4, 6) // List(6, 4, 2, 1, -3) } }