Consider this,

struct RandomGenerator : GeneratorType, SequenceType {



    mutating func next() -> UInt32? {

        return arc4random()

    }

}

what's the expected result of follows??


let random = RandomGenerator()


let resultA = random.first

let resultB = random.first

let resultC = Array(random.prefix(4))

let resultD = Array(random.prefix(4))

all should agree that resultC and resultD will get different array. what's
about with resultA and resultB?

Gwendal Roué <[email protected]> 於 2016年1月2日 下午8:13 寫道:

Hello,

My two cents: I feel uncomfortable with SequenceType.first since
SequenceType clearly states that it may be destructed on iteration.

Compare :

seq.generate().next() // clear that it may give another result if called
twice
seq.first             // unclear that it may give another result if called
twice

Gwendal
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to