<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">Hi Swift community,</div><div class=""><br class=""></div><div class="">Another pitch, this time related to the ownership manifesto.</div><div class=""><br class=""></div><div class=""><h1 id="add--code-mutablecollectionswap-with---code-" data-orig-id="add--code-mutablecollection.swap-_:with:---code-" style="box-sizing: border-box; font-size: 2.25em; margin-right: 0px; margin-bottom: 16px; margin-left: 0px; line-height: 1.2; position: relative; color: rgb(51, 51, 51); padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); font-family: helvetica, arial, freesans, clean, sans-serif; background-color: rgb(255, 255, 255); margin-top: 0px !important;" class="">Add <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 24.479999542236328px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">MutableCollection.swap(_:with:)</code></h1><ul style="box-sizing: border-box; padding: 0px 0px 0px 2em; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 12.799999237060547px; background-color: rgb(255, 255, 255);" class=""><li style="box-sizing: border-box;" class="">Proposal: <a href="file:///Users/ben_cohen/Documents/swift-evolution/proposals/NNNN-filename.md" style="box-sizing: border-box; background-color: transparent; color: rgb(65, 131, 196); text-decoration: none;" class="">SE-NNNN</a></li><li style="box-sizing: border-box;" class="">Authors: <a href="https://github.com/airspeedswift" style="box-sizing: border-box; background-color: transparent; color: rgb(65, 131, 196); text-decoration: none;" class="">Ben Cohen</a></li><li style="box-sizing: border-box;" class="">Review Manager: TBD</li><li style="box-sizing: border-box;" class="">Status: <strong style="box-sizing: border-box;" class="">Awaiting review</strong></li></ul><h2 id="introduction" style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; position: relative; color: rgb(51, 51, 51); padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); font-family: helvetica, arial, freesans, clean, sans-serif; background-color: rgb(255, 255, 255);" class="">Introduction</h2><p style="box-sizing: border-box; margin: 0px 0px 16px; color: rgb(51, 51, 51); font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 12.799999237060547px; background-color: rgb(255, 255, 255);" class="">As part of the introduction of the Law of Exclusivity, the current <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 10.880000114440918px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">swap(_:_:)</code> function must be addressed, as this most common use<ins id="firstdiff" style="box-sizing: border-box; display: inline-block; position: absolute; left: -8px; text-decoration: none !important; border: none !important; background-image: none !important; background-position: initial initial !important; background-repeat: initial initial !important;" class=""></ins>s of <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 10.880000114440918px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">swap</code> directly violate the law. This proposal introduces an alternative: a method on<code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 10.880000114440918px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">MutableCollection</code> that takes two indices for swapping two elements in the same collection,.</p><h2 id="motivation" style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; position: relative; color: rgb(51, 51, 51); padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); font-family: helvetica, arial, freesans, clean, sans-serif; background-color: rgb(255, 255, 255);" class="">Motivation</h2><p style="box-sizing: border-box; margin: 0px 0px 16px; color: rgb(51, 51, 51); font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 12.799999237060547px; background-color: rgb(255, 255, 255);" class="">The primary purpose of the current <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 10.880000114440918px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">swap</code> function is to swap two elements within a mutable collection. It was originally created to support the sort algorithm, which is why it is declared in <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 10.880000114440918px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">stdlib/sort.swift.gyb</code>. Here is some typical usage from that file:</p><pre style="box-sizing: border-box; overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 10.880000114440918px; margin-top: 0px; margin-bottom: 16px; font-stretch: normal; line-height: 1.45; padding: 16px; 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; word-wrap: normal; tab-size: 4; color: rgb(51, 51, 51); height: 73px;" class=""><code class="swift hljs" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; padding: 0.5em; margin: 0px; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; display: block; overflow-x: auto; line-height: inherit; word-wrap: normal; height: auto;"> <span class="hljs-keyword" style="box-sizing: border-box; font-weight: bold;">while</span> hi != lo {
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(0, 134, 179);">swap</span>(&elements[lo], &elements[hi])</code></pre><p style="box-sizing: border-box; margin: 0px 0px 16px; color: rgb(51, 51, 51); font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 12.799999237060547px; background-color: rgb(255, 255, 255);" class="">Under changes proposed as part of the ownership manfifesto, this will no longer be legal Swift: a single variable (in this case, <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 10.880000114440918px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">elements</code>) cannot be passed as two different <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 10.880000114440918px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">inout</code> arguments to the same function.</p><p style="box-sizing: border-box; margin: 0px 0px 16px; color: rgb(51, 51, 51); font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 12.799999237060547px; background-color: rgb(255, 255, 255);" class="">For more background on exclusivity and ownership, see the <a href="https://github.com/apple/swift/blob/master/docs/OwnershipManifesto.md" style="box-sizing: border-box; background-color: transparent; color: rgb(65, 131, 196); text-decoration: none;" class="">manfiesto</a></p><h2 id="proposed-solution" style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; position: relative; color: rgb(51, 51, 51); padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); font-family: helvetica, arial, freesans, clean, sans-serif; background-color: rgb(255, 255, 255);" class="">Proposed solution</h2><p style="box-sizing: border-box; margin: 0px 0px 16px; color: rgb(51, 51, 51); font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 12.799999237060547px; background-color: rgb(255, 255, 255);" class="">Introduce a new method on <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 10.880000114440918px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">MutableCollection</code> to the standard library that swaps the elements from two indices:</p><pre style="box-sizing: border-box; overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 10.880000114440918px; margin-top: 0px; margin-bottom: 16px; font-stretch: normal; line-height: 1.45; padding: 16px; 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; word-wrap: normal; tab-size: 4; color: rgb(51, 51, 51); height: 73px;" class=""><code class="swift hljs" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; padding: 0.5em; margin: 0px; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; display: block; overflow-x: auto; line-height: inherit; word-wrap: normal; height: auto;"> <span class="hljs-keyword" style="box-sizing: border-box; font-weight: bold;">while</span> hi != lo {
elements.<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(0, 134, 179);">swap</span>(lo, with: hi)</code></pre><p style="box-sizing: border-box; margin: 0px 0px 16px; color: rgb(51, 51, 51); font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 12.799999237060547px; background-color: rgb(255, 255, 255);" class="">As well as resolving the conflict with the proposed language change, this appears to improve readability.</p><p style="box-sizing: border-box; margin: 0px 0px 16px; color: rgb(51, 51, 51); font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 12.799999237060547px; background-color: rgb(255, 255, 255);" class="">Existing usage on two elements in a collection will need to be migrated to the new method.</p><p style="box-sizing: border-box; margin: 0px 0px 16px; color: rgb(51, 51, 51); font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 12.799999237060547px; background-color: rgb(255, 255, 255);" class="">While <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 10.880000114440918px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">swap</code> was only intended to be used on collections, it is possible to use on other variables. However, the recommended style for these uses is to not use a function at all:</p><pre style="box-sizing: border-box; overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 10.880000114440918px; margin-top: 0px; margin-bottom: 16px; font-stretch: normal; line-height: 1.45; padding: 16px; 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; word-wrap: normal; tab-size: 4; color: rgb(51, 51, 51); height: 133px;" class=""><code class="swift hljs" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; padding: 0.5em; margin: 0px; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; display: block; overflow-x: auto; line-height: inherit; word-wrap: normal; height: auto;"><span class="hljs-keyword" style="box-sizing: border-box; font-weight: bold;">var</span> a = <span class="hljs-number" style="box-sizing: border-box; color: rgb(0, 128, 128);">0</span>
<span class="hljs-keyword" style="box-sizing: border-box; font-weight: bold;">var</span> b = <span class="hljs-number" style="box-sizing: border-box; color: rgb(0, 128, 128);">1</span>
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(0, 134, 179);">swap</span>(&a,&b)
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(153, 153, 136); font-style: italic;">// can be rewritten as:</span>
(a,b) = (b,a)</code></pre><p style="box-sizing: border-box; margin: 0px 0px 16px; color: rgb(51, 51, 51); font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 12.799999237060547px; background-color: rgb(255, 255, 255);" class="">The existing <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 10.880000114440918px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">swap</code> method will remain, as under some circumstances it may result in a performance gain, particularly if move-only types are introduced in a later release.</p><h2 id="detailed-design" style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; position: relative; color: rgb(51, 51, 51); padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); font-family: helvetica, arial, freesans, clean, sans-serif; background-color: rgb(255, 255, 255);" class="">Detailed design</h2><p style="box-sizing: border-box; margin: 0px 0px 16px; color: rgb(51, 51, 51); font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 12.799999237060547px; background-color: rgb(255, 255, 255);" class="">Add the following method to the standard library:</p><pre style="box-sizing: border-box; overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 10.880000114440918px; margin-top: 0px; margin-bottom: 16px; font-stretch: normal; line-height: 1.45; padding: 16px; 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; word-wrap: normal; tab-size: 4; color: rgb(51, 51, 51); height: 133px;" class=""><code class="swift hljs" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; padding: 0.5em; margin: 0px; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; display: block; overflow-x: auto; line-height: inherit; word-wrap: normal; height: auto;"><span class="hljs-class" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; font-weight: bold;">extension</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(68, 85, 136); font-weight: bold;">MutableCollection</span> </span>{
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(153, 153, 136); font-style: italic;">/// Exchange the values at indices `a` and `b`.</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(153, 153, 136); font-style: italic;">///</span>
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(153, 153, 136); font-style: italic;">/// Has no effect when `a` and `b` are equal.</span>
<span class="hljs-keyword" style="box-sizing: border-box; font-weight: bold;">public</span> <span class="hljs-keyword" style="box-sizing: border-box; font-weight: bold;">mutating</span> <span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; font-weight: bold;">func</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(153, 0, 0); font-weight: bold;">swap</span><span class="hljs-params" style="box-sizing: border-box;">(<span class="hljs-number" style="box-sizing: border-box; color: rgb(0, 128, 128);">_</span> i: Index, with b: Index)</span></span>
}</code></pre><p style="box-sizing: border-box; margin: 0px 0px 16px; color: rgb(51, 51, 51); font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 12.799999237060547px; background-color: rgb(255, 255, 255);" class="">The current <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 10.880000114440918px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">swap</code> is required to <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 10.880000114440918px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">fatalError</code> on attempts to swap an element with itself for implementation reasons. This pushes the burden to check this first onto the caller. While swapping an element with itself is often a logic errror (for example, in a <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 10.880000114440918px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">sort</code> algorithm where you have a fenceposts bug), it is occasionally a valid situation (for example, it can occur easily in an implementation of <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 10.880000114440918px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">shuffle</code>). This implementation removes the precondition.</p><p style="box-sizing: border-box; margin: 0px 0px 16px; color: rgb(51, 51, 51); font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 12.799999237060547px; background-color: rgb(255, 255, 255);" class="">Deprecate the existing <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 10.880000114440918px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">swap</code>, and obsolete it in a later version of Swift.</p><h2 id="source-compatibility" style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; position: relative; color: rgb(51, 51, 51); padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); font-family: helvetica, arial, freesans, clean, sans-serif; background-color: rgb(255, 255, 255);" class="">Source compatibility</h2><p style="box-sizing: border-box; margin: 0px 0px 16px; color: rgb(51, 51, 51); font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 12.799999237060547px; background-color: rgb(255, 255, 255);" class="">This is purely additive so should not be source breaking. However, due to current compiler behavior, it may be necessary to declare a version of the old <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 10.880000114440918px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">swap</code> on <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 10.880000114440918px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">MutableCollection</code> for Swift 3 compatibility purposes. This version will forward to the free function.</p><h2 id="effect-on-abi-stability" style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; position: relative; color: rgb(51, 51, 51); padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); font-family: helvetica, arial, freesans, clean, sans-serif; background-color: rgb(255, 255, 255);" class="">Effect on ABI stability</h2><p style="box-sizing: border-box; margin: 0px 0px 16px; color: rgb(51, 51, 51); font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 12.799999237060547px; background-color: rgb(255, 255, 255);" class="">None.</p><h2 id="effect-on-api-resilience" style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; position: relative; color: rgb(51, 51, 51); padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); font-family: helvetica, arial, freesans, clean, sans-serif; background-color: rgb(255, 255, 255);" class="">Effect on API resilience</h2><p style="box-sizing: border-box; margin: 0px 0px 16px; color: rgb(51, 51, 51); font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 12.799999237060547px; background-color: rgb(255, 255, 255);" class="">N/A</p><h2 id="alternatives-considered" style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; position: relative; color: rgb(51, 51, 51); padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); font-family: helvetica, arial, freesans, clean, sans-serif; background-color: rgb(255, 255, 255);" class="">Alternatives considered</h2><p style="box-sizing: border-box; margin: 0px 0px 16px; color: rgb(51, 51, 51); font-family: helvetica, arial, freesans, clean, sans-serif; font-size: 12.799999237060547px; background-color: rgb(255, 255, 255);" class="">Instead of <code style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 10.880000114440918px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;" class="">elements.swap(i, with: j)</code>, the following were considered:</p><pre style="box-sizing: border-box; overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 10.880000114440918px; margin-top: 0px; font-stretch: normal; line-height: 1.45; padding: 16px; 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; word-wrap: normal; tab-size: 4; color: rgb(51, 51, 51); height: 88px; margin-bottom: 0px !important;" class=""><code class="swift hljs" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; padding: 0.5em; margin: 0px; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; border: 0px; display: block; overflow-x: auto; line-height: inherit; word-wrap: normal; height: auto;">elements.<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(0, 134, 179);">swap</span>(at: i, j)
elements.swapElements(i, j)
elements.<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(0, 134, 179);">swap</span>(elements: i, j)</code></pre><div class=""><br class=""></div></div></body></html>