Swiftz是一个Swift库,实现了函数式编程。
示例代码:
let xs = [1, 2, 0, 3, 4]// we ca use the Mi semigroup to fid the miimal elemet i xsscocat(Mi(), 2, xs) // 0// we ca use the Sum mooid to fid the sum of xsmcocat(Sum<It8, NIt8>(i: { retur it8 }), xs) // 10// we ca delay computatios with futureslet x: Future<It> = Future(exec: gcdExecutioCotext, { sleep(1) retur 4})x.result() == x.result() // true, returs i 1 secod// we ca map ad flatMap over futuresx.map({ $0.descriptio }).result() // "4", returs istatlyx.flatMap({ (x: It) -> Future<It> i retur Future(exec: gcdExecutioCotext, { sleep(1); retur x + 1 })}).result() // sleeps aother secod, the returs 5









评论