Created
August 23, 2018 13:28
-
-
Save dsebban/bb34ea4671bda8d52e2f083e2b160778 to your computer and use it in GitHub Desktop.
copy/paste into ammonite REPL to run : http://ammonite.io/#Ammonite-REPL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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