Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
filterM / State
scala> type RunState[A] = State[(Int, Int), A] // ((lastNum, run length), A)defined type alias RunState
scala> val ls = List(1, 1, 2, 2, 2, 3, 3, 3, 3, 1, 1)
ls: List[Int] = List(1, 1, 2, 2, 2, 3, 3, 3, 3, 1, 1)
scala> std.list.filterM[Int, RunState](ls)(x =>
State { case (y, n) =>
val nn = if (x == y) n + 1 else 0
((x, nn), nn == 0) }
).eval((ls.head, -1))
res29: scalaz.Id.Id[List[Int]] = List(1, 2, 3, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.