From 1fc8fd55ccf53fb41f8745851cd44dab79eb27d5 Mon Sep 17 00:00:00 2001 From: Cody Allen Date: Sat, 12 Sep 2015 15:01:35 -0400 Subject: [PATCH 1/3] Streaming.take(n).toList shouldn't blow up when n+1 is an error --- core/src/main/scala/cats/data/Streaming.scala | 4 +++- tests/shared/src/test/scala/cats/tests/StreamingTests.scala | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/main/scala/cats/data/Streaming.scala b/core/src/main/scala/cats/data/Streaming.scala index 235d241624..460e3e089b 100644 --- a/core/src/main/scala/cats/data/Streaming.scala +++ b/core/src/main/scala/cats/data/Streaming.scala @@ -473,7 +473,9 @@ 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) => + if (n == 1) Cons(a, Now(Empty())) + else Cons(a, lt.map(_.take(n - 1))) } /** diff --git a/tests/shared/src/test/scala/cats/tests/StreamingTests.scala b/tests/shared/src/test/scala/cats/tests/StreamingTests.scala index 16adba5406..e566ecd958 100644 --- a/tests/shared/src/test/scala/cats/tests/StreamingTests.scala +++ b/tests/shared/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)) From 58351eda2b12598eabb7f05d0b8a10247a9a232e Mon Sep 17 00:00:00 2001 From: Cody Allen Date: Sun, 13 Sep 2015 07:47:32 -0400 Subject: [PATCH 2/3] Minor cleanup to Streaming.take A gift for @non. --- core/src/main/scala/cats/data/Streaming.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/main/scala/cats/data/Streaming.scala b/core/src/main/scala/cats/data/Streaming.scala index 460e3e089b..8ef36cd535 100644 --- a/core/src/main/scala/cats/data/Streaming.scala +++ b/core/src/main/scala/cats/data/Streaming.scala @@ -474,8 +474,7 @@ sealed abstract class Streaming[A] { lhs => case Empty() => Empty() case Wait(lt) => Wait(lt.map(_.take(n))) case Cons(a, lt) => - if (n == 1) Cons(a, Now(Empty())) - else Cons(a, lt.map(_.take(n - 1))) + Cons(a, if (n ==1) Now(Empty()) else lt.map(_.take(n - 1))) } /** From 21f89332a53c51f02e2595c0d17dfcb6c1a601fb Mon Sep 17 00:00:00 2001 From: Cody Allen Date: Tue, 15 Sep 2015 07:20:56 -0400 Subject: [PATCH 3/3] A space for @adelbertc --- core/src/main/scala/cats/data/Streaming.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/scala/cats/data/Streaming.scala b/core/src/main/scala/cats/data/Streaming.scala index 8ef36cd535..7193e2ca7f 100644 --- a/core/src/main/scala/cats/data/Streaming.scala +++ b/core/src/main/scala/cats/data/Streaming.scala @@ -474,7 +474,7 @@ sealed abstract class Streaming[A] { lhs => case Empty() => Empty() case Wait(lt) => Wait(lt.map(_.take(n))) case Cons(a, lt) => - Cons(a, if (n ==1) Now(Empty()) else lt.map(_.take(n - 1))) + Cons(a, if (n == 1) Now(Empty()) else lt.map(_.take(n - 1))) } /**