> On Feb 22, 2017, at 10:42 AM, Nate Cook via swift-evolution
> <[email protected]> wrote:
>
> Oops, left out that there's this horrifying way of writing it right now:
>
> extension Collection {
> func index(_ i: Index! = nil, offsetBy n: IndexDistance) -> Index {
> let i = i ?? startIndex
> // ...
> }
> }
>
> Nobody wants that.
>
Oh I don’t think it’s all that bad! It also doesn’t need to be an IUO, since
you’re unwrapping it immediately into another variable no matter what.
This also gives you the flexibility to write this:
extension Collection {
func index(_ i: Index? = nil, offsetBy n: IndexDistance) -> Index {
let i = i ?? (n < 0 ? endIndex : startIndex)
// ...
}
}
> _______________________________________________
> swift-evolution mailing list
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution