diff --git a/core/src/main/scala/cats/data/StreamingT.scala b/core/src/main/scala/cats/data/StreamingT.scala index 3c104fd194..214a0c8021 100644 --- a/core/src/main/scala/cats/data/StreamingT.scala +++ b/core/src/main/scala/cats/data/StreamingT.scala @@ -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 } diff --git a/tests/src/test/scala/cats/tests/StreamingTTests.scala b/tests/src/test/scala/cats/tests/StreamingTTests.scala index 753bdae828..7140b9d496 100644 --- a/tests/src/test/scala/cats/tests/StreamingTTests.scala +++ b/tests/src/test/scala/cats/tests/StreamingTTests.scala @@ -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))