Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix StreamingT.filter bug #798

Merged
merged 1 commit into from
Jan 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion core/src/main/scala/cats/data/StreamingT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ sealed abstract class StreamingT[F[_], A] extends Product with Serializable { lh
*/
def filter(f: A => Boolean)(implicit ev: Functor[F]): StreamingT[F, A] =
this match {
case Cons(a, ft) => if (f(a)) this else Wait(ft.map(_.filter(f)))
case Cons(a, ft) =>
val tail = ft.map(_.filter(f))
if (f(a)) Cons(a, tail) else Wait(tail)
case Wait(ft) => Wait(ft.map(_.filter(f)))
case Empty() => this
}
Expand Down
5 changes: 5 additions & 0 deletions tests/src/test/scala/cats/tests/StreamingTTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ class StreamingTTests extends CatsSuite {
}
}

test("filter - check regression") {
val s = StreamingT[Option, Int](1, 2, 1)
s.filter(_ > 1).toList should === (Some(List(2)))
}

test("foldLeft with Id consistent with List.foldLeft") {
forAll { (s: StreamingT[Id, Int], l: Long, f: (Long, Int) => Long) =>
s.foldLeft(l)(f) should === (s.toList.foldLeft(l)(f))
Expand Down