Scala Stream

An other data structure today ! After seeingList,Set. Let's talk aboutStream, now calledLazyListin Scala 2.13+.

This is a bit of a longer exercise because there are several ways to create aLazyListand several ways to use it. Remember, this isyourjourney. If you only have the time to complete the beginning, you can move on or come back to it later.

In the first section, you saw how to create aLazyListrecursively using the symbol#::. You also learned that you cantakeas many elements as you want, but since Scala valuesimmutability, doing it several times in a row will always returns the same elements. Make sure to read the log statements carefully.

In the second section, we are usingLazyList.fromto use the build-in tools that allow you to start a sequentialstreamstarting atnand increasing one by one. You also see thatmapcan be used to modify the outcome of theLazyList. And finally,takecan only reduce the size of the stream.

In the third and final section, we are implementingfactorial, once recursively and then using aLazyList. Have you notice the use of thefoldLeftfrom previous SKB !?

Reveal more information and clues
Load Exercise