<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I’ve seen the WWDC 2016 Keynote and State of the Platforms videos. I haven’t seen any others so I don’t spoil myself before typing my ideas down. Apologies if this has already been covered.</div><div class=""><br class=""></div><div class="">I saw that the “PermutationGenerator” type is being retired in Swift 3. It inspired me to see how I can implement such a type:</div><div class=""><br class=""></div><div class="">//=====</div>/// Permutations generator, adapted from a Java class that mentioned its source as <<a href="http://www.cut-the-knot.org/Curriculum/Combinatorics/JohnsonTrotter.shtml" class="">http://www.cut-the-knot.org/Curriculum/Combinatorics/JohnsonTrotter.shtml</a>>. Inspired by checking that Swift 3 will not have/retain such a type.<br class="">struct PermutationsGenerator<Index: ForwardIndexType>: GeneratorType {<br class=""><br class=""> /// postconditions: The first `self.next` returns an array of the indices in order.<br class=""> init(indices: Range<Index>)<br class=""><br class=""><div class=""> mutating func next() -> [Index]?<br class=""><br class="">}<br class="">//=====</div><div class=""><br class=""></div><div class="">Use like:</div><div class=""><br class=""></div><div class="">//=====</div><div class="">func doSomething<C: CollectionType>(collection: C) {</div><div class=""> var g = PermutationsGenerator(collection.indices)</div><div class=""> while let p = g.next() {</div><div class=""> doSomethingToo(p.map { collection[$0] })</div><div class=""> }</div><div class="">}</div><div class="">//=====</div><div class=""><br class="">So the first call to “next” returns “Array(indices)” and subsequent calls return scrambled versions of that array. There will be “factorial(indices.count)” versions returned. (For an empty range or one with one valid element, there will be only 0! == 1! == 1 valid return.)</div><div class=""><br class=""></div><div class="">Then I looked further. This is NOT what the existing “PermutationGenerator” does. In fact, the type is being retired for this very reason. The type actually returns a subset of collection, possibly in a scrambled order (i.e. a permutation). Some questions:</div><div class=""><br class=""></div><div class="">1. Is the functionality of the existing “PermutationGenerator” being moved to another type?</div><div class="">2. Would my type be suitable to add to the standard library? Would the name need to be changed? (The name is appropriate, but it’s just one letter different from a depreciated type.)<br class=""><br class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">— </div><div class="">Daryle Walker<br class="">Mac, Internet, and Video Game Junkie<br class="">darylew AT mac DOT com </div></div>
</div>
<br class=""></div></body></html>