Sbequizch12 - codeport/scala GitHub Wiki

  1. Stream은 어떤 식으로 lazy evaluation을 수행할 수 있을까요?

  2. Stream과 비슷한 녀석 StreamLike를 만들어 봅시다. (난이도 상)

  3. 다음은 Scaladoc의 Stream에 나오는 예제 코드이다. 읽고 이해해보자.

       object Main extends Application {  
         def from(n: Int): Stream[Int] =
           Stream.cons(n, from(n + 1))     
         def sieve(s: Stream[Int]): Stream[Int] =
           Stream.cons(s.head, sieve(s.tail filter { _ % s.head != 0 }))
         def primes = sieve(from(2))
         primes take 10 print
       }