title: In Swift, outwards pingpong sequence?
body: <p>Say you have</p>
  
  <pre><code>for i in 0 ... 10 {
   print(i)
  }
  </code></pre>
  
  <p>of course it will print 0,1,2,3,4,5,6,7,8,9,10</p>
  
  <pre><code>for i in 0 ..&lt; 5 {
  </code></pre>
  
  <p>that's 0,1,2,3,4.</p>
  
  <p>I want to start at a certain integer and pingpong outwards over the count of numbers</p>
  
  <p>So,</p>
  
  <pre><code>for i in function or something (10, 3)
  </code></pre>
  
  <p>that's <strong>3</strong> 4 2 5 1 6 0 7 8 9 </p>
  
  <pre><code>for i in function or something (10, 8) {
  </code></pre>
  
  <p>would be <strong>8</strong> 9 7 6 5 4 3 2 1 0</p>
  
  <pre><code>for i in function or something (10, 2) {
  </code></pre>
  
  <p>would be <strong>2</strong> 3 1 4 0 5 6 7 8 9</p>
  
  <p>So it's just an outwards pingpong.</p>
  
  <p>What should I type where I have written <code>function or something (10, 2)</code>?</p>
  
  <p>There might be some really cool syntax possible, along the lines <code>0 # 7 # 10</code>.</p>
  
  <p>What about something like <code>(0..&lt;10).outPong(3)</code>?</p>
  
  <p>How to formulate such a sequence?</p>
  
  <hr>
  
  <p>Here's a naive example of how you'd do an outwards pingpong, at the call level.</p>
  
  <p>Call <code>exampleLoad</code> for each of the items in RA, outwards pingpoing:</p>
  
  <pre><code>func loadItemsPongwise(startWith: Int) {
  
      // RA = ... this is your array of some type
  
      exampleLoad(startWith)
      let k = RA.count
      var howManyDone: Int = 0
      var distance: Int = 1
  
      while howManyDone &lt; ( k - 1 ) {
  
          let tryRight = alreadyLoaded + distance
          if tryRight &lt; k {
              howManyDone = howManyDone + 1
              exampleLoad(RA[tryRight])
          }
  
          let tryLeft = alreadyLoaded - distance
          if tryLeft &gt;= 0 {
              howManyDone = howManyDone + 1
              exampleLoad(RA[tryLeft])
          }
  
          distance = distance + 1
      }
  }
  </code></pre>
  
  <p>Of course, something like this wouild be much nicer:</p>
  
  <pre><code>func loadItemsPongwise(startWith: Int) {
      for i in ???? {
        exampleLoad(i)
      }
  }
  </code></pre>