<div dir="ltr"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px">Consider the follows:</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">struct</span> Person {</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px">    </p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    <span style="color:rgb(187,44,162)">var</span> name: <span style="color:rgb(112,61,170)">String</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    <span style="color:rgb(187,44,162)">var</span> age: <span style="color:rgb(112,61,170)">Int</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">let</span> peoples = [<span style="color:rgb(79,129,135)">Person</span>(name: <span style="color:rgb(209,47,27)">&quot;Hawk&quot;</span>, age: <span style="color:rgb(39,42,216)">24</span>), <span style="color:rgb(79,129,135)">Person</span>(name: <span style="color:rgb(209,47,27)">&quot;Andrew&quot;</span>, age: <span style="color:rgb(39,42,216)">23</span>)]</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">let</span> youngest = <span style="color:rgb(79,129,135)">peoples</span>.<span style="color:rgb(61,29,129)">minElement</span> { $0.<span style="color:rgb(79,129,135)">age</span> &lt; $1.<span style="color:rgb(79,129,135)">age</span> }</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span style="color:rgb(61,29,129)">print</span><span style="color:rgb(0,0,0)">(</span>youngest<span style="color:rgb(0,0,0)">?.</span>name<span style="color:rgb(0,0,0)">)</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span style="color:rgb(0,0,0)"><br></span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span style="color:rgb(0,0,0)">it&#39;s silly that we always have to write the code like </span><span style="color:rgb(0,0,0)">{ $0.some &lt; $1.</span><span style="color:rgb(0,0,0)">some</span><span style="color:rgb(0,0,0)"> } or </span><span style="color:rgb(0,0,0)">{ </span><span style="color:rgb(0,0,0)">some</span><span style="color:rgb(0,0,0)">($0) &lt; </span><span style="color:rgb(0,0,0)">some</span><span style="color:rgb(0,0,0)">($1)</span><span style="color:rgb(0,0,0)"> }</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px">so, we should add those methods to stdlib:</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112,61,170)"><span style="color:rgb(187,44,162)">extension</span><span style="color:rgb(0,0,0)"> </span>SequenceType<span style="color:rgb(0,0,0)"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span>/// Returns the minimum element in `self` or `nil` if the sequence is empty.</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    <span style="color:rgb(0,132,0)">///</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span>/// - Complexity: O(`elements.count`).</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    <span style="color:rgb(0,132,0)">///</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><span style="color:rgb(0,0,0)">    </span>@warn_unused_result</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    <span style="color:rgb(187,44,162)">public</span> <span style="color:rgb(187,44,162)">func</span> minElement&lt;R : <span style="color:rgb(112,61,170)">Comparable</span>&gt;(<span style="color:rgb(187,44,162)">@noescape</span> by: (Generator.Element) <span style="color:rgb(187,44,162)">throws</span> -&gt; R) <span style="color:rgb(187,44,162)">rethrows</span> -&gt; <span style="color:rgb(112,61,170)">Generator</span>.<span style="color:rgb(112,61,170)">Element</span>? {</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">        <span style="color:rgb(187,44,162)">return</span> <span style="color:rgb(187,44,162)">try</span> <span style="color:rgb(187,44,162)">self</span>.<span style="color:rgb(61,29,129)">minElement</span> { <span style="color:rgb(187,44,162)">try</span> by($0) <span style="color:rgb(61,29,129)">&lt;</span> by($1) }</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    }</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span>/// Returns the maximum element in `self` or `nil` if the sequence is empty.</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    <span style="color:rgb(0,132,0)">///</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span>/// - Complexity: O(`elements.count`).</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    <span style="color:rgb(0,132,0)">///</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><span style="color:rgb(0,0,0)">    </span>@warn_unused_result</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    <span style="color:rgb(187,44,162)">public</span> <span style="color:rgb(187,44,162)">func</span> maxElement&lt;R : <span style="color:rgb(112,61,170)">Comparable</span>&gt;(<span style="color:rgb(187,44,162)">@noescape</span> by: (Generator.Element) <span style="color:rgb(187,44,162)">throws</span> -&gt; R) <span style="color:rgb(187,44,162)">rethrows</span> -&gt; <span style="color:rgb(112,61,170)">Generator</span>.<span style="color:rgb(112,61,170)">Element</span>? {</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">        <span style="color:rgb(187,44,162)">return</span> <span style="color:rgb(187,44,162)">try</span> <span style="color:rgb(187,44,162)">self</span>.<span style="color:rgb(61,29,129)">maxElement</span> { <span style="color:rgb(187,44,162)">try</span> by($0) <span style="color:rgb(61,29,129)">&lt;</span> by($1) }</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    }</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112,61,170)"><span style="color:rgb(187,44,162)">public</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(187,44,162)">extension</span><span style="color:rgb(0,0,0)"> </span>MutableCollectionType<span style="color:rgb(0,0,0)"> {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px">    </p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span>/// Return an `Array` containing the sorted elements of `source`.</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span>/// according to `by`.</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    <span style="color:rgb(0,132,0)">///</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span>/// The sorting algorithm is not stable (can change the relative order of</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span>/// elements that compare equal).</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)"><span style="color:rgb(0,0,0)">    </span>@warn_unused_result(mutable_variant=&quot;sortInPlace&quot;)</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(112,61,170)"><span style="color:rgb(0,0,0)">    </span><span style="color:rgb(187,44,162)">func</span><span style="color:rgb(0,0,0)"> sort&lt;R : </span>Comparable<span style="color:rgb(0,0,0)">&gt;(</span><span style="color:rgb(187,44,162)">@noescape</span><span style="color:rgb(0,0,0)"> by: (</span>Generator<span style="color:rgb(0,0,0)">.</span>Element<span style="color:rgb(0,0,0)">) -&gt; </span>R<span style="color:rgb(0,0,0)">) -&gt; [</span>Generator<span style="color:rgb(0,0,0)">.</span>Element<span style="color:rgb(0,0,0)">] {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">        <span style="color:rgb(187,44,162)">return</span> <span style="color:rgb(187,44,162)">self</span>.<span style="color:rgb(61,29,129)">sort</span> { by($0) <span style="color:rgb(61,29,129)">&lt;</span> by($1) }</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    }</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">public</span> <span style="color:rgb(187,44,162)">extension</span> <span style="color:rgb(112,61,170)">MutableCollectionType</span> <span style="color:rgb(187,44,162)">where</span> <span style="color:rgb(187,44,162)">Self</span>.Index : RandomAccessIndexType {</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px">    </p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span>/// Sort `self` in-place according to `by`.</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    <span style="color:rgb(0,132,0)">///</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span>/// The sorting algorithm is not stable (can change the relative order of</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:rgb(0,0,0)">    </span>/// elements that compare equal).</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    <span style="color:rgb(187,44,162)">mutating</span> <span style="color:rgb(187,44,162)">func</span> sortInPlace&lt;R : <span style="color:rgb(112,61,170)">Comparable</span>&gt;(<span style="color:rgb(187,44,162)">@noescape</span> by: (<span style="color:rgb(112,61,170)">Generator</span>.<span style="color:rgb(112,61,170)">Element</span>) -&gt; <span style="color:rgb(112,61,170)">R</span>) {</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">        <span style="color:rgb(187,44,162)">self</span>.<span style="color:rgb(61,29,129)">sortInPlace</span> { by($0) <span style="color:rgb(61,29,129)">&lt;</span> by($1) }</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">    }</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</p><div><br></div></div>