Assignment 2 is designed to test your understanding of the second week of CSYE7200 lectures, in particular Scala’s mechanism for dealing with lazy values. Furthermore, working through the assignment, you will understand that features like Streams in Scala are not “magic.” We can create our own, simply using a function for the lazily-evaluated tail.
You can find the code under the assignment-lazy directory in the REPO. Make sure you do a pull first.
[21] You are to submit evidence of all unit tests (in LazyListSpec) passing (use a screenshot). In order to get the tests to succeed, you must implement the from method in the companion object of LazyList. Replace the ??? //… with your own working code. There are plenty of other examples of similar functionality in the LazyList module. Submit, along with your unit test screenshots, the expression that you used to implement the from method.
Additionally, I want to see answers to the following questions:
1. (a) [3] what is the chief way by which LazyList differs from Stream (the built-in Scala class that does the same thing). Don’t mention the methods that LazyList does or doesn’t implement–I want to know what is the structural difference. (b) [3] Why do you think there is this difference?
2. [5] Explain what the following code actually and why is it needed?
3. def tail = lazyTail()
4.
5. [3] List all of the recursive calls that you can find in LazyList (give line numbers).
6. [4] List all of the mutable variables and mutable collections that you can find in LazyList (give line numbers).
7. [5] What is the purpose of the zip method?
8. [6] Why is there no length (or size) method for LazyList?