Global function sequence(state:next:) and type inference

前端 未结 2 1797
攒了一身酷
攒了一身酷 2020-12-11 23:51

Background & details

Swift evolution proposal SE-0094 was implemented in Swift 3.0, introducing the global sequence functions:

  • sequenc
2条回答
  •  死守一世寂寞
    2020-12-12 00:07

    But even admitting that this is a bug, you can still make the code look a lot nicer instead of worrying about it (typed in the browser without testing, but something like this should work):

    typealias MyTriple = (Bool, ClosedRangeIterator, ClosedRangeIterator)
    let someTriple : MyTriple = (false, seq1.makeIterator(), seq2.makeIterator())
    let combined = sequence(state: someTriple) { 
        (iters: inout MyTriple) -> Int? in
        iters.0 = !iters.0
        return iters.0 ? iters.1.next() : iters.2.next()
    }
    

提交回复
热议问题