diff --git a/core/src/main/scala/cats/data/Streaming.scala b/core/src/main/scala/cats/data/Streaming.scala index 235d241624..7193e2ca7f 100644 --- a/core/src/main/scala/cats/data/Streaming.scala +++ b/core/src/main/scala/cats/data/Streaming.scala @@ -473,7 +473,8 @@ sealed abstract class Streaming[A] { lhs => if (n <= 0) Empty() else this match { case Empty() => Empty() case Wait(lt) => Wait(lt.map(_.take(n))) - case Cons(a, lt) => Cons(a, lt.map(_.take(n - 1))) + case Cons(a, lt) => + Cons(a, if (n == 1) Now(Empty()) else lt.map(_.take(n - 1))) } /** diff --git a/tests/src/test/scala/cats/tests/StreamingTests.scala b/tests/src/test/scala/cats/tests/StreamingTests.scala index 16adba5406..e566ecd958 100644 --- a/tests/src/test/scala/cats/tests/StreamingTests.scala +++ b/tests/src/test/scala/cats/tests/StreamingTests.scala @@ -262,6 +262,10 @@ class AdHocStreamingTests extends CatsProps { isok(bomb.take(0)) } + property("take up to the last valid element"){ + isok(dangerous.take(3).toList) + } + property("lazy drop") { isok(bomb.drop(10)) isok(bomb.drop(0))