Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dsebban
Created August 23, 2018 13:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsebban/bb34ea4671bda8d52e2f083e2b160778 to your computer and use it in GitHub Desktop.
Save dsebban/bb34ea4671bda8d52e2f083e2b160778 to your computer and use it in GitHub Desktop.
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