Skip to content

Instantly share code, notes, and snippets.

import shapeless._
import scalaz._
import Scalaz._
object console extends App {
trait Foo[A] {
type B
def value: B
@jopecko
jopecko / showProcessedCount.scala
Last active July 27, 2022 18:05 — forked from kubukoz/showProcessedCount.scala
Periodically show the amount of elements produced by an fs2 stream
def showProcessedCount[F[_]: Concurrent: Timer, A]: Pipe[F, A, A] = stream =>
fs2.Stream.eval(Ref[F].of(0)).flatMap { count =>
stream.chunks
.evalMap { chunk =>
count.update(_ + chunk.size).as(chunk)
}
.flatMap(fs2.Stream.chunk)
.concurrently(
fs2.Stream