From 49879a8694b229fc074dc2d6d7b2973a56557a5b Mon Sep 17 00:00:00 2001 From: Trenton Lipscomb Date: Wed, 28 Oct 2009 22:44:43 -0700 Subject: [PATCH] using Stream rather than fixed Range --- scala/002/01.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scala/002/01.scala b/scala/002/01.scala index 681839c..d4abfdf 100644 --- a/scala/002/01.scala +++ b/scala/002/01.scala @@ -18,8 +18,7 @@ def acc_tr_helper(n: Int, sum: Int): Int = n match { } val maxAllowedValue = 4000000 -// perhaps a Projection to infinity instead? -val fibLessThanMax = (1 to Integer.MAX_VALUE).map(fib(_)).takeWhile(_ < maxAllowedValue) +val fibLessThanMax = Stream.from(1).map(fib(_)).takeWhile(_ < maxAllowedValue) println(fibLessThanMax.filter(_ % 2 == 0).foldLeft(0L)(_ + _)) // http://oldfashionedsoftware.com/2009/07/30/lots-and-lots-of-foldleft-examples/