Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
copy/paste into ammonite REPL to run : http://ammonite.io/#Ammonite-REPL
import $ivy.`co.fs2:fs2-core_2.12:0.10.5` , fs2._
def dedupeConsecutiveWhen[F[_], I](f: (I, I) => Boolean): Pipe[F, I, I] = in =>
in.zipWithNext.map {
case (curr, Some(next)) if f(curr, next) => (None: Option[I])
case (curr, Some(next)) => Some(curr)
case (curr, None) => Some(curr)
}.unNone
Stream(1,1,2,2,3,4,5,2).through(dedupeConsecutiveWhen(_ == _ )).toList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment