Re: [比较] 我为何钟情于用 Scala 做为兵刃(三)

楼主: huei1224 (渣)   2011-07-10 22:18:41
: ====================== 我是 Scala 程式分隔线 =========================
: val xs = List(-1, -2, -3, 0, 1, 2, 3)
: val square = (n: Int) => n * n
: val isGreaterThan5 = (n: Int) => n > 5
: val result = xs.map(square).filter(isGreaterThan5).length
: // 上面那行和下面这行等价
: // val result = xs.map(n => n * n).filter(n => n > 5).length
: println (result1)
: ======================================================================
最近在学 haskell ,发现 haskell 也可以写成像上面的型式,分享一下
let x -: f = f x
let xs = [-3..3]
let square = (^2)
let isGreaterThan5 = (>5)
let result = xs -: map square -: filter isGreaterThan5 -: length

Links booklink

Contact Us: admin [ a t ] ucptt.com