From 378d52c98022b78b067ccc85e886e2bc1cd4ac71 Mon Sep 17 00:00:00 2001 From: Cody Allen Date: Mon, 16 Nov 2015 09:02:38 -0500 Subject: [PATCH] Failing test: repeat evaluation with Streaming.memoize This is a potential bug report and is not meant to be merged in its current form. This test fails. It attempts to check that if a `Streaming` instance is created via `.memoize`, then its elements won't be evaluated multiple times (such as when `.toList` is called). One could argue that this is a bogus test case, since side effects should be tracked in a type other than `Unit`. However, I believe that this means that we might be evaluating arguments overly-eagerly, which is a problem in itself. I made a naive attempt at fixing this by making `Streaming.map` a little lazier in the `Cons` case, but that didn't seem to do the trick. @non do you have any thoughts? --- tests/src/test/scala/cats/tests/StreamingTests.scala | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/src/test/scala/cats/tests/StreamingTests.scala b/tests/src/test/scala/cats/tests/StreamingTests.scala index e4eff26282..86bd1fd69b 100644 --- a/tests/src/test/scala/cats/tests/StreamingTests.scala +++ b/tests/src/test/scala/cats/tests/StreamingTests.scala @@ -43,6 +43,18 @@ class AdHocStreamingTests extends CatsSuite { } } + test("results aren't reevaluated after memoize") { + forAll { (orig: Streaming[Int]) => + val size = orig.toList.size + var i = 0 + val memoized = orig.map(_ => i += 1).memoize + memoized.toList + i should === (size) + memoized.toList + i should === (size) + } + } + // convert (A => List[B]) to (A => Streaming[B]) def convertF[A, B](f: A => List[B]): A => Streaming[B] = (a: A) => Streaming.fromList(f(a))