<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br></div><div>On Apr 17, 2016, at 8:46 AM, plx via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><div class="">I like the idea. It worries me a bit if the general recipe for such situations is to add dedicated-purpose methods like `_customIndexOfMinComparableElement` (etc.) to standard-library protocols; it *will* work, but is only going to work for the methods that get such treatment.</div></div></blockquote><div><br></div><div>Agreed! I'm not sure if that's part of the generics manifesto or not, but it'd be great to have conditionally applied dynamically dispatched methods for cases like this.</div><br><blockquote type="cite"><div><div class="">If it were feasible, I’d *greatly* prefer having some more-general way to (conditionally?) add overridable methods to a protocol, e.g.:</div><div class=""><br class=""></div><div class="">&nbsp; // made-up declaration, all declared methods below are now overridable</div><div class="">&nbsp; // on suitable types</div><div class="">&nbsp; overridable extension Collection where Iterator.Element: Comparable {</div><div class="">&nbsp; &nbsp;&nbsp;</div><div class="">&nbsp; &nbsp; func min() -&gt; Iterator.Element? &nbsp; &nbsp;</div><div class=""><br class=""></div><div class="">&nbsp; }</div><div class=""><br class=""></div><div class="">…but am not sure that’s even realistically possible.</div><div class=""><br class=""></div><div class="">The reason I bring it up is that I’d hope that `indexOf`, `contains`, and also `upperBound`/`lowerBound` would merit a similar treatment to that proposed here for min, max, and minmax (if not already given such; if they get added to standard-library; etc.).</div></div></blockquote><div><br></div><div>The customization points in the proposal are modeled after the two existing ones in the standard library for `contains` and `index(of:)`. You can see them here:</div><div><br></div><div><a href="https://github.com/apple/swift/blob/master/stdlib/public/core/Sequence.swift#L190">https://github.com/apple/swift/blob/master/stdlib/public/core/Sequence.swift#L190</a></div><div><a href="https://github.com/apple/swift/blob/master/stdlib/public/core/Collection.swift#L184">https://github.com/apple/swift/blob/master/stdlib/public/core/Collection.swift#L184</a></div><br><blockquote type="cite"><div><div class="">Moving on, wrt these min/max elements themselves: I think any expectation about *which* index gets returned should be document—either no such expectation in general, or a specific expectation, or that each concrete collection should document the expectation, etc.—because for the minIndex/maxIndex methods different approaches can yield different results.</div><div class=""><br class=""></div><div class="">EG: consider an order-maintaining collection that has contents ~ `[1,1,1,2,2,2,3,3,3]`. There are multiple candidates for both `minIndex` and `maxIndex`.</div><div class=""><br class=""></div><div class="">I don’t have a strong opinion on what the right preference would be here, but I think whatever the behavior winds up being should be at least documented.</div><div class=""><br class=""></div><div class="">Finally, FWIW if more of these semi-hidden methods become something exposed to users (as “advanced” options, perhaps, but still) I think replacing `??` with something like</div><div class=""><br class=""></div><div class="">&nbsp; enum AdvancedCustomizationPointResult&lt;T&gt; {</div><div class="">&nbsp; &nbsp; case NotCustomized // like `nil` for ??</div><div class="">&nbsp; &nbsp; case NoResult // like `Optional(nil)` for ??</div><div class="">&nbsp; &nbsp; case Result(T) // like `Optional(T)` for ??</div><div class="">&nbsp; }</div><div class=""><br class=""></div><div class="">…might be worth considering (except with a better name than that). I’m not trying to backdoor optional protocol methods or anything, it just seems advisable to more-explicitly represent the intent (?? certainly works but feels a bit obscure).</div><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 17, 2016, at 1:44 AM, Nate Cook via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><font face="Helvetica, arial, sans-serif" class=""><span style="background-color: rgb(255, 255, 255);" class="">Hello all,</span></font><div class=""><font face="Helvetica, arial, sans-serif" class=""><span style="background-color: rgb(255, 255, 255);" class=""><br class=""></span></font></div><div class=""><font face="Helvetica, arial, sans-serif" class=""><span style="background-color: rgb(255, 255, 255);" class="">Attached is a draft of a proposal to expand the min and max sequence APIs to better handle collections and to support future sorted sequences/collections. The proposal&nbsp;</span></font><a href="https://gist.github.com/natecook1000/d51267a6cf9e9463b9387bced4c65b16" class="">is in a gist here</a><font face="Helvetica, arial, sans-serif" class=""><span style="background-color: rgb(255, 255, 255);" class="">&nbsp;and&nbsp;inlined below—would love to hear any comments or feedback before submitting the proposal.</span></font></div><div class=""><font face="Helvetica, arial, sans-serif" class=""><span style="background-color: rgb(255, 255, 255);" class=""><br class=""></span></font></div><div class=""><font face="Helvetica, arial, sans-serif" class=""><span style="background-color: rgb(255, 255, 255);" class="">Nate</span></font></div><div class=""><font face="Helvetica, arial, sans-serif" class=""><span style="background-color: rgb(255, 255, 255);" class=""><br class=""></span></font></div><div class=""><font face="Helvetica, arial, sans-serif" class=""><span style="background-color: rgb(255, 255, 255);" class=""><br class=""></span></font><h1 id="toc_0" style="-webkit-print-color-adjust: exact; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255); margin-top: 0px !important;" class="">Proposal: Expanded min/max algorithms</h1><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">This proposal would expand on the&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">min()</code>&nbsp;and&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">max()</code>&nbsp;sequence methods to add methods that return the corresponding index for a collection, efficiently find the minimum and maximum elements or indices at the same time, and provide extension points for sorted collections to provide all these results more efficiently.</p><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class=""><strong style="-webkit-print-color-adjust: exact;" class="">Related Bugs:</strong>&nbsp;<a href="https://bugs.swift.org/browse/SR-889" style="-webkit-print-color-adjust: exact; color: rgb(65, 131, 196);" class="">SR-889</a>&nbsp;and&nbsp;<a href="https://bugs.swift.org/browse/SR-890" style="-webkit-print-color-adjust: exact; color: rgb(65, 131, 196);" class="">SR-890</a></p><h2 id="toc_2" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 24px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(204, 204, 204); font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Motivation</h2><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">The&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">Sequence</code>&nbsp;protocol currently offers&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">min()</code>&nbsp;and&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">max()</code>&nbsp;methods that return the minimum and maximum elements of a sequence or collection. Unfortunately, there are applications where these methods do not provide enough flexibility to be useful.</p><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">First, if the user of a collection wants not just to get the minimum value but also to operate on it in some way (e.g., mutation or just accessing it multiple times), she would need the index of the minimum element. The current APIs don't support that, so she would need to write her own.</p><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">Second, the writer of a sorted collection is currently unable to provide efficient responses to the&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">min()</code>&nbsp;and&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">max()</code>&nbsp;methods when used in a generic context, even though these should be O(1) operations. Just like&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">Set</code>&nbsp;can respond quickly to&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">contains(_:)</code>&nbsp;even in a generic context, so too should new sorted collections be able to optimize their responses.</p><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">Finally, getting the minimum and maximum elements (or indices) of a collection or sequence currently requires calling both&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">min()</code>&nbsp;and&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">max()</code>. With two calls, every element is iterated and compared twice. When you need both results, finding both the minimum and the maximum at the same time is more efficient, requiring only a single pass and 25% fewer comparisons.</p><h2 id="toc_3" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 24px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(204, 204, 204); font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Proposed solution</h2><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">This proposal has three parts:</p><ol style="-webkit-print-color-adjust: exact; margin: 15px 0px; padding-left: 30px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class=""><li style="-webkit-print-color-adjust: exact; margin: 0px;" class=""><p style="-webkit-print-color-adjust: exact; margin: 0px 0px 15px;" class="">Adding&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">minIndex()</code>&nbsp;and&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">maxIndex()</code>&nbsp;methods to&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">Collection</code>&nbsp;that return the index of the minimum and maximum elements, respectively.</p><div style="-webkit-print-color-adjust: exact;" class=""><pre class=" language-swift" style="-webkit-print-color-adjust: exact; margin-top: 0.5em; margin-bottom: 0.5em; background-color: rgb(245, 242, 240); border: 1px solid rgb(204, 204, 204); font-size: 13px; line-height: 1.5; overflow: auto; padding: 1em; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; text-shadow: white 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; tab-size: 4; -webkit-hyphens: none;"><code class=" language-swift" style="-webkit-print-color-adjust: exact; margin: 0px; padding: 0px; border: none; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-image: none; text-shadow: white 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; line-height: 1.5; tab-size: 4; -webkit-hyphens: none;"><span class="token keyword" style="-webkit-print-color-adjust: exact; margin-top: 0px; color: rgb(0, 119, 170);">let</span> numbers <span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">=</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">[</span><span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(153, 0, 85);">30</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">,</span> <span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(153, 0, 85);">40</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">,</span> <span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(153, 0, 85);">10</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">,</span> <span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(153, 0, 85);">20</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">,</span> <span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(153, 0, 85);">60</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">,</span> <span class="token number" style="-webkit-print-color-adjust: exact; color: rgb(153, 0, 85);">50</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">]</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">if</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">let</span> i <span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">=</span> numbers<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">.</span><span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(221, 74, 104);">minIndex</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">{</span>
    <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(221, 74, 104);">print</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span><span class="token string" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">"<span class="token interpolation" style="-webkit-print-color-adjust: exact; margin-top: 0px;"><span class="token delimiter variable" style="-webkit-print-color-adjust: exact; margin-top: 0px; color: rgb(238, 153, 0);">\(</span>i<span class="token delimiter variable" style="-webkit-print-color-adjust: exact; color: rgb(238, 153, 0);">)</span></span>: <span class="token interpolation" style="-webkit-print-color-adjust: exact;"><span class="token delimiter variable" style="-webkit-print-color-adjust: exact; margin-top: 0px; color: rgb(238, 153, 0);">\(</span>numbers<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">[</span>i<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">]</span><span class="token delimiter variable" style="-webkit-print-color-adjust: exact; color: rgb(238, 153, 0);">)</span></span>"</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span>               <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">// 2: 10</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">}</span></code></pre></div></li><li style="-webkit-print-color-adjust: exact; margin: 0px;" class=""><p style="-webkit-print-color-adjust: exact; margin: 0px 0px 15px;" class="">Adding&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">minmax()</code>&nbsp;and&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">minmaxIndices()</code>&nbsp;methods to&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">Sequence</code>&nbsp;and&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">Collection</code>, respectively, to calculate the values (or indices) of the minimum and maximum elements simultaneously.</p><div style="-webkit-print-color-adjust: exact;" class=""><pre class=" language-swift" style="-webkit-print-color-adjust: exact; margin-top: 0.5em; margin-bottom: 0.5em; background-color: rgb(245, 242, 240); border: 1px solid rgb(204, 204, 204); font-size: 13px; line-height: 1.5; overflow: auto; padding: 1em; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; text-shadow: white 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; tab-size: 4; -webkit-hyphens: none;"><code class=" language-swift" style="-webkit-print-color-adjust: exact; margin: 0px; padding: 0px; border: none; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-image: none; text-shadow: white 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; line-height: 1.5; tab-size: 4; -webkit-hyphens: none;"><span class="token keyword" style="-webkit-print-color-adjust: exact; margin-top: 0px; color: rgb(0, 119, 170);">if</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">let</span> result <span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">=</span> numbers<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">.</span><span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(221, 74, 104);">minmax</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">{</span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">// result == (minimum: 10, maximum: 60)</span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">// ...</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">}</span>
<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">if</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">let</span> i <span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">=</span> numbers<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">.</span><span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(221, 74, 104);">minmaxIndices</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">{</span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">// i == (minimum: 2, maximum: 4)</span>
    <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(221, 74, 104);">print</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span><span class="token string" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">"<span class="token interpolation" style="-webkit-print-color-adjust: exact; margin-top: 0px;"><span class="token delimiter variable" style="-webkit-print-color-adjust: exact; margin-top: 0px; color: rgb(238, 153, 0);">\(</span>i<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">.</span>minimum<span class="token delimiter variable" style="-webkit-print-color-adjust: exact; color: rgb(238, 153, 0);">)</span></span>: <span class="token interpolation" style="-webkit-print-color-adjust: exact;"><span class="token delimiter variable" style="-webkit-print-color-adjust: exact; margin-top: 0px; color: rgb(238, 153, 0);">\(</span>numbers<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">[</span>i<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">.</span>minimum<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">]</span><span class="token delimiter variable" style="-webkit-print-color-adjust: exact; color: rgb(238, 153, 0);">)</span></span>"</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">}</span></code></pre></div></li><li style="-webkit-print-color-adjust: exact; margin: 0px;" class=""><p style="-webkit-print-color-adjust: exact; margin: 0px 0px 15px;" class="">Adding customization points for sequences and collections that can offer more efficient results:&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">_customMinComparableElement()</code>/<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">_customMaxComparableElement()</code>&nbsp;for&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">Sequence</code>&nbsp;and&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">_customIndexOfMinComparableElement()</code>/<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">_customIndexOfMaxComparableElement()</code>for&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">Collection</code>.</p></li></ol><h2 id="toc_4" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 24px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(204, 204, 204); font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Detailed design</h2><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">The following methods would be added to the visible public APIs of&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">Sequence</code>&nbsp;and&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">Collection</code>&nbsp;as default implementations.</p><div style="-webkit-print-color-adjust: exact; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class=""><pre class=" language-swift" style="-webkit-print-color-adjust: exact; margin-top: 0.5em; margin-bottom: 0.5em; background-color: rgb(245, 242, 240); border: 1px solid rgb(204, 204, 204); font-size: 13px; line-height: 1.5; overflow: auto; padding: 1em; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; text-shadow: white 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; tab-size: 4; -webkit-hyphens: none;"><code class=" language-swift" style="-webkit-print-color-adjust: exact; margin: 0px; padding: 0px; border: none; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-image: none; text-shadow: white 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; line-height: 1.5; tab-size: 4; -webkit-hyphens: none;"><span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Sequence</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">{</span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// Returns the minimum and maximum values of `self`, using </span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// `isOrderedBefore` to compare elements, or `nil` if the sequence</span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// has no elements.</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">func</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(221, 74, 104);">minmax</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span>@noescape isOrderedBefore isOrderedBefore<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> 
        <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Iterator</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">.</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Element</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">,</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Iterator</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">.</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Element</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">throws</span> <span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">-</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">&gt;</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Bool</span>
        <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">rethrows</span> <span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">-</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">&gt;</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">min</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Iterator</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">.</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Element</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">,</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">max</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Iterator</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">.</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Element</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">?</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Sequence</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">where</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Iterator</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">.</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Element</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Comparable</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">{</span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// Returns the minimum and maximum values of `self`, or `nil` </span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// if the sequence has no elements.</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">func</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(221, 74, 104);">minmax</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span> <span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">-</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">&gt;</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">min</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Iterator</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">.</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Element</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">,</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">max</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Iterator</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">.</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Element</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">?</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Collection</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">{</span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// Returns the index of the minimum element of `self`, using </span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// `isOrderedBefore` to compare elements, or `nil` if the</span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// collection has no elements.</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">func</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(221, 74, 104);">minIndex</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span>@noescape isOrderedBefore isOrderedBefore<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> 
        <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Iterator</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">.</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Element</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">,</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Iterator</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">.</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Element</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">throws</span> <span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">-</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">&gt;</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Bool</span>
        <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">rethrows</span> <span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">-</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">&gt;</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Index</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">?</span>
        
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// Returns the index of the maximum element of `self`, using </span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// `isOrderedBefore` to compare elements, or `nil` if the</span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// collection has no elements.</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">func</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(221, 74, 104);">maxIndex</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span>@noescape isOrderedBefore isOrderedBefore<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> 
        <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Iterator</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">.</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Element</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">,</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Iterator</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">.</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Element</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">throws</span> <span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">-</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">&gt;</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Bool</span>
        <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">rethrows</span> <span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">-</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">&gt;</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Index</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">?</span>

    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// Returns the indices of the minimum and maximum elements of `self`, </span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// using `isOrderedBefore` to compare elements, or `nil` if the</span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// collection has no elements.</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">func</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(221, 74, 104);">minmaxIndices</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span>@noescape isOrderedBefore isOrderedBefore<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> 
        <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Iterator</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">.</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Element</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">,</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Iterator</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">.</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Element</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">throws</span> <span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">-</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">&gt;</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Bool</span>
        <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">rethrows</span> <span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">-</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">&gt;</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span>minIndex<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Index</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">,</span> maxIndex<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Index</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">?</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">}</span>

<span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">extension</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Collection</span> <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">where</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Iterator</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">.</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Element</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Comparable</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">{</span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// Returns the index of the minimum element of `self`, or `nil` </span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// if the collection has no elements.</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">func</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(221, 74, 104);">minIndex</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span> <span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">-</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">&gt;</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Index</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">?</span>
        
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// Returns the index of the maximum element of `self`, or `nil` </span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// if the collection has no elements.</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">func</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(221, 74, 104);">maxIndex</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span> <span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">-</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">&gt;</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Index</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">?</span>

    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// Returns the indices of the minimum and maximum elements of `self`, </span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// or `nil` if the collection has no elements.</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">func</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(221, 74, 104);">minmaxIndices</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span> <span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">-</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">&gt;</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span>minIndex<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Index</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">,</span> maxIndex<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">:</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Index</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">?</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">}</span></code></pre></div><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">The customization points would be added to&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">Sequence</code>&nbsp;and&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">Collection</code>&nbsp;as protocol requirements, along with default implementations that return&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">nil</code>. The existing&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">min()</code>and&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">max()</code>&nbsp;methods would be updated to call the corresponding methods before iterating over the entire sequence.</p><div style="-webkit-print-color-adjust: exact; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class=""><pre class=" language-swift" style="-webkit-print-color-adjust: exact; margin-top: 0.5em; margin-bottom: 0.5em; background-color: rgb(245, 242, 240); border: 1px solid rgb(204, 204, 204); font-size: 13px; line-height: 1.5; overflow: auto; padding: 1em; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; text-shadow: white 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; tab-size: 4; -webkit-hyphens: none;"><code class=" language-swift" style="-webkit-print-color-adjust: exact; margin: 0px; padding: 0px; border: none; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-image: none; text-shadow: white 0px 1px; font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; word-spacing: normal; word-break: normal; word-wrap: normal; line-height: 1.5; tab-size: 4; -webkit-hyphens: none;">protocol <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Sequence</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">{</span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">// ...</span>
    
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// Returns the minimum element as `Optional(element)` or `Optional(nil)`</span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// if the sequence has no elements. The uncustomized version returns</span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// `nil`.</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">func</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(221, 74, 104);">_customMinComparableElement</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span> <span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">-</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">&gt;</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Iterator</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">.</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Element</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">?</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">?</span>
    
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// Returns the maximum element as `Optional(element)` or `Optional(nil)`</span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// if the sequence has no elements. The uncustomized version returns</span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// `nil`.</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">func</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(221, 74, 104);">_customMaxComparableElement</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span> <span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">-</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">&gt;</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Iterator</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">.</span><span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Element</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">?</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">?</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">}</span>

protocol <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Collection</span> <span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">{</span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">// ...</span>
    
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// Returns the index of the minimum element as `Optional(index)` or</span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// `Optional(nil)` if the sequence has no elements. The uncustomized </span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// version returns `nil`.</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">func</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(221, 74, 104);">_customIndexOfMinComparableElement</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span> <span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">-</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">&gt;</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Index</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">?</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">?</span>
    
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// Returns the index of the maximum element as `Optional(index)` or</span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// `Optional(nil)` if the sequence has no elements. The uncustomized </span>
    <span class="token comment" spellcheck="true" style="-webkit-print-color-adjust: exact; color: rgb(112, 128, 144);">/// version returns `nil`.</span>
    <span class="token keyword" style="-webkit-print-color-adjust: exact; color: rgb(0, 119, 170);">func</span> <span class="token function" style="-webkit-print-color-adjust: exact; color: rgb(221, 74, 104);">_customIndexOfMaxComparableElement</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">(</span><span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">)</span> <span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">-</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">&gt;</span> <span class="token builtin" style="-webkit-print-color-adjust: exact; color: rgb(102, 153, 0);">Index</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">?</span><span class="token operator" style="-webkit-print-color-adjust: exact; color: rgb(166, 127, 89); background-color: rgba(255, 255, 255, 0.498039); background-position: initial initial; background-repeat: initial initial;">?</span>
<span class="token punctuation" style="-webkit-print-color-adjust: exact; color: rgb(153, 153, 153);">}</span></code></pre></div><h4 id="toc_5" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 16px; font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Minmax Algorithm</h4><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">The&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">minmax()</code>&nbsp;algorithm finds the minimum and maximum elements of a sequence in one pass more efficiently than consecutive calls to&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">min()</code>&nbsp;and&nbsp;<code style="-webkit-print-color-adjust: exact; margin: 0px 2px; padding: 0px 5px; white-space: nowrap; border: 1px solid rgb(234, 234, 234); background-color: rgb(248, 248, 248); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">max()</code>. This optimization comes from iterating over a sequence two elements at a time.&nbsp;</p><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">In each iteration, two consecutive elements are compared with each other. Only the lesser element could be a minimum for the whole sequence, so it is compared with the current minimum, while only the greater element could be a maximum, so it is compared with the current maximum. This works out to 3 comparisons for every 2 elements vs. 2 comparisons for every element when the minimum and maximum are found individually.</p><h2 id="toc_6" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 24px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(204, 204, 204); font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Impact on existing code</h2><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">As new APIs these should have no effect on existing code.</p><h2 id="toc_7" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 24px; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(204, 204, 204); font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Alternatives considered</h2><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">None.</p></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>