title: Grouping event with fs2.Stream
body: <p>I have event stream as follows:</p>
  
  <pre><code>sealed trait Event
  
  val eventStream: fs2.Stream[IO, Event] = //...
  </code></pre>
  
  <p>I want to group this events received within a single minute (i.e from 0 sec to 59 sec of every minute). This sounds pretty straightforward with <code>fs2</code></p>
  
  <pre><code>val groupedEventsStream = eventStream groupAdjacentBy {event =&gt; 
      TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis())
  }
  </code></pre>
  
  <p>The problem is that the <strong><em>grouping function is not pure</em></strong>. It uses <code>currentTimeMillis</code>. I can workaroud this as follows:</p>
  
  <pre><code>stream.evalMap(t =&gt; IO(System.currentTimeMillis(), t))
    .groupAdjacentBy(t =&gt; TimeUnit.MILLISECONDS.toMinutes(t._1))
  </code></pre>
  
  <p>The thing is that adds clumsy boilerplate with tuples I'd like to avoid. Is there any other solutions? </p>
  
  <p>Or maybe using impure function is not that bad for such a case? </p>