[swift-evolution] Proposal: Add SequenceType.first

Susan Cheng susan.doggie at gmail.com
Sat Jan 2 06:24:44 CST 2016


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é <gwendal.roue at gmail.com> 於 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160102/f38decf3/attachment.html>


More information about the swift-evolution mailing list