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
       }