<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          SwiftzSwift函數(shù)式編程

          聯(lián)合創(chuàng)作 · 2023-09-28 17:33

          Swiftz 是一個(gè) Swift 庫(kù),實(shí)現(xiàn)了函數(shù)式編程。

          示例代碼:

          let xs = [1, 2, 0, 3, 4]
          
          // we can use the Min semigroup to find the minimal element in xs
          sconcat(Min(), 2, xs) // 0
          
          // we can use the Sum monoid to find the sum of xs
          mconcat(Sum<Int8, NInt8>(i: { return nint8 }), xs) // 10
          
          // we can delay computations with futures
          let x: Future<Int> = Future(exec: gcdExecutionContext, {
            sleep(1)
            return 4
          })
          x.result() == x.result() // true, returns in 1 second
          
          // we can map and flatMap over futures
          x.map({ $0.description }).result() // "4", returns instantly
          x.flatMap({ (x: Int) -> Future<Int> in
            return Future(exec: gcdExecutionContext, { sleep(1); return x + 1 })
          }).result() // sleeps another second, then returns 5
          瀏覽 24
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  国精产品久久久久久 | 亚洲成人网在线免费观看 | 亚洲高清视频在线观看免费 | 操操网网址| 成人日皮精品视频 |