title: How do I separate a stream of `1`s and `2`s into groups?
body: <p>Imagine I have a <em>really</em> long file like this:</p>
  
  <pre><code>1
  1
  1
  1
  2
  2
  2
  2
  1
  1
  1
  1
  2
  2
  1
  1
  2
  2
  ...
  </code></pre>
  
  <p>I'm interested in separating and performing computation on each group of consecutive <code>1</code>s along with the consecutive <code>2</code>s that come immediately after it.</p>
  
  <p><em>However</em>, the problem is somewhat more complicated in reality. First, the records are not simply <code>1</code>s and <code>2</code>s but something larger, let's say individual <code>Record</code>s, and it requires some computation to determine whether a <code>Record</code> is <code>1</code> or <code>2</code>; second, instead of exposed as a file, the data source only exposes it self with a retrieving function, let's say <code>get1 :: IO (Maybe Record)</code>. This function returns one record <code>Just record</code> with each call, and returns <code>Nothing</code> when the data is depleted; and finally, the file is large (effectively infinite), I have to do it in a stream-lined way with constant memory usage.</p>
  
  <p>Here is a supposed transcript demonstrating how I want it to behave: (the <code>1</code>s and <code>2</code>s are the <code>Record</code>s retrieved from <code>get1</code> calls, and the <code>(,)</code>s represent computations happened immediately after each detection of group)</p>
  
  <pre><code>1
  1
  1
  2
  2
  1
  (["1","1","1"],["2","2"])
  2
  1
  (["1"],["2"])
  1
  1
  1
  2
  2
  2
  2
  1
  (["1","1","1","1"],["2","2","2","2"])
  </code></pre>