title: RxSwift, count how many equal consecutive Equatable items are emitted
body: <p>I have an Observable that emits a sequence of Equatable elements.
  The stream may contain consecutive sequences of equal elements (for instance in the sequence [1, 1, 1, 18, 2, 2, 0, -1] element 1 is repeated 3 times, 2 is repeated 2 times).
  I need to compress the sequence substituting for every distinct element a tuple containing the element and the number of repetitions that were present in the original stream:</p>
  
  <pre><code>1, 1, 1, 18, 21, 21, 0, -1, -8, -8, 14, 14, 14...
  
  (1, 3), (18, 1), (21, 2), (0, 1), (-1, 1), (-8, 2), (14, 3)...
  </code></pre>
  
  <p>I managed to count repetitions with the <code>scan</code> operator, but it emits all the partial computations that shouldn't be part of the final sequence:</p>
  
  <pre class="lang-swift prettyprint-override"><code>let numbers = Observable&lt;Int&gt;.from([
      0, 0,
      3, 3, 3, 3, 3,
      2,
      0, 0, 0,
      6, 6,
      ])
  
  let reps = numbers
      .scan((0, 0), accumulator: {
          (prev: (Int, Int), new: (Int)) in
          if prev.0 == new {
              return (new, prev.1 + 1)
          } else {
              return (new, 1)
          }
      })
  
  reps.subscribe(onNext: {
          print("\($0)")
      })
  
  // expected:
  // (0, 2), (3, 5), (2, 1), (0, 3), (6, 2)
  //
  // result:
  // (0, 1), (0, 2),
  // (3, 1), (3, 2), (3, 3), (3, 4), (3, 5),
  // (2, 1),
  // (0, 1), (0, 2), (0, 3),
  // (6, 1), (6, 2)
  </code></pre>