title: Pausing and resuming a sequence in Kotlin
body: <p>The yield function in Kotlin states the following:</p>
  
  <blockquote>
    <p>Yields a value to the Iterator being built and suspends until the next
    value is requested.</p>
  </blockquote>
  
  <p>In the following Kotlin code:</p>
  
  <pre><code>val sequence = sequence {
      val start = 0
      // yielding a single value
      yield(start)
      // yielding an iterable
      yieldAll(1..5 step 2)
      // yielding an infinite sequence
      yieldAll(generateSequence(8) { it * 3 })
  }
  </code></pre>
  
  <p>The yield statement is inside the sequence function. What I would like to do is have a Pause button that prevents further sequence items from being processed and a Resume button that when pressed allows the processing of the next item in the sequence. However if yield is inside of the sequence function, it isn't clear how a Pause/Resume flag can be used with this.</p>