title: Map list to tuples of following elements
body: <p>I have given a list of integers. I need to map always two following elements in further progressing. If the input list contains a invalid count of elements the last ones should be dropped. Here is an example:</p>
  
  <pre><code>[1, 2, 3, 4, 5, 6, 7] //Input
  [(1, 2), (3, 4), (5, 6)] //Output
  </code></pre>
  
  <p>I wrote to functions to get the wanted output but I think they are both inefficient.</p>
  
  <p>First i tried it with a functional approach. But it needs two filter calls and a zip call for the resulting list. So it iterates 2.5 times over the entier list.</p>
  
  <p>Two imrpove this I tried a iterative approach. It only iterates once over the list and is possibly the fastest version. But it uses multiple mutable variables/lists. Also it is not as easy to understand as the functinal approach. (And it breaks the cleaness of the rest of the code)</p>
  
  <pre><code>fun main(args: Array&lt;String&gt;) {
      mapFunctional()
      mapIterative()
  }
  
  fun mapFunctional() {
      val list: List&lt;Int&gt; = listOf(1, 2, 3, 4, 5, 6, 7)
  
      val output: List&lt;Pair&lt;Int, Int&gt;&gt; = list.filterIndexed { index, _ -&gt;
          index % 2 == 0
      }.zip(list.filterIndexed {
          index, _ -&gt; index % 2 == 1
      })
  
      println(output)
  }
  
  fun mapIterative() {
      val list: List&lt;Int&gt; = listOf(1, 2, 3, 4, 5, 6, 7)
  
      val output: MutableList&lt;Pair&lt;Int, Int&gt;&gt; = mutableListOf()
      var index = 0
      while (index &lt; list.size - 1) {
          output.add(list[index++] to list[index++])
      }
  
      println(output)
  }
  </code></pre>
  
  <p>Is their a good (efficient) way to achieve this in a functinal aprroach or is it only possible with a classic loop?</p>