<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On 11 Apr 2016, at 15:23, Luis Henrique B. Sousa via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><div class=""><div dir="ltr" class=""><div class=""><p class=""><font face="monospace, monospace" class=""><span class="">let</span><span class=""> a </span><span class="">=</span><span class=""> [</span><span class="">1</span><span class="">,</span><span class="">2</span><span class="">,</span><span class="">3</span><span class="">]<br class=""></span><span class="">let</span><span class=""> b </span><span class="">=</span><span class=""> a[</span><span class="">0</span><span class="">..<</span><span class="">5</span><span class="">]<br class=""></span><span class="">print</span><span class="">(b)</span></font></p></div></div></div></blockquote></div><div class="">In the <a href="https://github.com/apple/swift/blob/swift-3-indexing-model/stdlib/public/core/Range.swift#L94" class="">swift-3-indexing-model branch</a>, you can <i class="">clamp</i> a range just like you could clamp intervals in Swift 2. So the following will work in the way you preferred:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""> let b = a[</span></font><span style="font-family: Menlo; font-size: 11px;" class="">a.indices</span><span style="font-size: 11px; font-family: Menlo;" class="">.clamped(to: </span><span style="font-family: Menlo; font-size: 11px;" class="">0 ..< 5</span><span style="font-family: Menlo; font-size: 11px;" class="">)]</span></div><div class=""><br class=""></div><div class="">It was suggested to extend `<font face="Menlo" class=""><span style="font-size: 11px;" class="">Collection</span></font>` with a subscript like `<span style="font-family: Menlo; font-size: 11px;" class="">a[safe: 0 ..< 5]</span>` which resembles the current <a href="https://github.com/apple/swift/blob/swift-3-indexing-model/stdlib/public/core/Collection.swift#L82" class="">subsequence subscript</a>. Alternatively, we could bring collections even closer to ranges by extending them with the equivalent `<font face="Menlo" class=""><span style="font-size: 11px;" class="">.clamped(to:)</span></font>` method:</div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""><br class=""></span></font></div><div class=""><font face="Menlo" class=""><span style="font-size: 11px;" class=""> let b = a.clamped(to: 0 ..< 5) // "safe" subsequence</span></font></div><div class=""><br class=""></div>— Pyry<div><blockquote type="cite" class=""></blockquote></div><div class=""><br class=""></div></body></html>