May I suggest a simple solution?

        extension SequenceType {
                /// Returns one element from the beginning of the sequence, or 
`nil` if the sequence is empty.
                /// If `self` is a single-pass sequence, this may consume the 
element.
                func one() -> Generator.Element? {
                        var generator = generate()
                        return generator.next()
                }
        }

This should probably be a method in the protocol, and CollectionType should 
have an override which calls `first`.

The BufferedSequence stuff suggested elsewhere is probably useful too, and 
should be considered in addition to this, but I think this would cover the most 
common case.

-- 
Brent Royal-Gordon
Architechies

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

Reply via email to