tag:blogger.com,1999:blog-5089773352404981635.post7183831881924982578..comments2023-10-04T08:15:13.812-07:00Comments on Daily scala: Introducing StreamsAnonymoushttp://www.blogger.com/profile/07600430363435495915noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-5089773352404981635.post-28277855473083944512013-03-09T12:59:02.940-08:002013-03-09T12:59:02.940-08:00make is a function that returns a Stream of random...make is a function that returns a Stream of randomizer. Calling make(0) instantiates a stream and takes the first value of that stream. The stream is then send to garbage. So each make(0) will start all over again. You expected that the result of make is preserved. You need to assign the Stream to a val like 'val r = make'. Then each call to r(0) will result in the same value.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5089773352404981635.post-86135203795083169282011-03-10T10:09:59.972-08:002011-03-10T10:09:59.972-08:00What is "infinate"? Maybe it should be &...What is "infinate"? Maybe it should be "infinite"?Qrilkahttps://www.blogger.com/profile/14856370078919907461noreply@blogger.comtag:blogger.com,1999:blog-5089773352404981635.post-90830344681909281292010-04-07T00:12:59.670-07:002010-04-07T00:12:59.670-07:00It looks like the implementation changed since I w...It looks like the implementation changed since I wrote this. Life on the bleeding edge :PAnonymoushttps://www.blogger.com/profile/07600430363435495915noreply@blogger.comtag:blogger.com,1999:blog-5089773352404981635.post-49568704280058150892010-04-07T00:09:18.882-07:002010-04-07T00:09:18.882-07:00I get different results from the example: def make...I get different results from the example: def make : Stream[Int] = Stream.cons(util.Random.nextInt(10), make)<br />For me, the nextInt call is evaluated each time f(0) (for instance) is called, returning a different random int. In order to get a single result, evaluated only once, I had to wrap the call in a closure. Odd you got the result you did...Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5089773352404981635.post-49812451754834256732010-04-07T00:06:11.367-07:002010-04-07T00:06:11.367-07:00From the example, def make : Stream[Int] = Stream....From the example, def make : Stream[Int] = Stream.cons(util.Random.nextInt(10), make), doesn't actually work as recorded for me (on 2.8 beta). Each call to make(0) returns a different value, as the function is evaluated each time. In order to have the value evaluated just once, I needed to write the call to nextInt in a closure. Odd that you got the results you did...Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5089773352404981635.post-56835372537430279942010-01-25T20:22:43.741-08:002010-01-25T20:22:43.741-08:00Thanks for this post, it taught me some things. In...Thanks for this post, it taught me some things. In particular, the new #:: notation seems very convenient...Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5089773352404981635.post-81721740238365056152010-01-19T00:14:13.175-08:002010-01-19T00:14:13.175-08:00I believe you can do exactly that. I will test a ...I believe you can do exactly that. I will test a bit more but I think you might be able to do:<br /><br />val theRest = stream.drop(100)<br /><br />theRest should have dropped the first part of the stream so that it can be garbage collected (once all references to stream are gone).<br /><br />I have to test to verify but that is my understandingAnonymoushttps://www.blogger.com/profile/07600430363435495915noreply@blogger.comtag:blogger.com,1999:blog-5089773352404981635.post-31733838699499462672010-01-18T13:25:54.462-08:002010-01-18T13:25:54.462-08:00Is there some way to use streams without keeping t...Is there some way to use streams without keeping the previous values for ever? Something like getting a reference to the 'tail' equivalent and loose the stream reference?Erik van Oostenhttps://www.blogger.com/profile/15976519439979651010noreply@blogger.com