[swift-evolution] Proposal: Add syntactic sugar for iterating over an Optional<SequenceType>

Marco Masser lists at duckcode.com
Wed Dec 16 13:55:30 CST 2015

> FWIW, the above only works when "array" is an array or set.  In a generic
> context you might not even know how to construct an empty one.
Right. And for types that don't conform to ArrayLiteralConvertible or
DictionaryLiteralConvertible, there's no chance to do a shortcut like that.

a?.forEach { object in ... }
> is the generic version I think.

Unfortunately, this prevents break/continue from being very readable in the
"loop" body (IMHO) and doesn't allow a return out of the enclosing function
at all. But yeah, at least that works on any Optional<SequenceType>.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151216/532e6040/attachment.html>

More information about the swift-evolution mailing list