[swift-evolution] [swift-users] for in? optionalCollection {
Guillaume Lessard
glessard at tffenterprises.com
Mon Feb 13 00:42:13 CST 2017
This could come for almost free after SE-0143 is implemented: an Optional of a Sequence could itself be made to conform to Sequence. It would cost no new syntax.
extension Optional: Sequence where Wrapped: Sequence {
func makeIterator() -> AnyIterator<Wrapped.Iterator.Element> {
switch self {
case .some(let sequence):
return AnyIterator(sequence.makeIterator())
case .none:
return AnyIterator { nil }
}
}
}
This would be more easily done than new syntax, surely.
Cheers,
Guillaume Lessard
More information about the swift-evolution
mailing list