Thursday, October 18, 2007

Streams for Incremental and Tail-Recoursive Computing

Programming in Scala is a lot of fun for me, but I really love Streams. Their laziness allows really nice implementations of incremental algorithms and tail-recursive functions. the best thing is they can be used efficiently under different requirements: no matter if you are interested in each intermediate result or only the final one, you'll only need one implementations. =)

I hope the following example computing the factorial(s) using Streams explains it well:

No comments: