Skip to content

Commit

Permalink
Merge pull request #798 from ceedubs/streamingt-filter-bug
Browse files Browse the repository at this point in the history
Fix StreamingT.filter bug
  • Loading branch information
ceedubs committed Jan 12, 2016
2 parents ebb92ba + 815b8fb commit ceff342
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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

0 comments on commit ceff342

Please sign in to comment.