1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~
 1 package colorscheme.example
 2 
 3 import Stream._
 4 trait Stream[+A] {
 5 
 6   // The natural recursive solution
 7   def toListRecursive: List[A] = this match {
 8     case Cons(head, tail) => head() :: tail().toListRecursive
 9     case _ => List()
10   }
11 
12   def toList: List[A] = {
13     @annotation.tailrec
14     def go(stream: Stream[A], acc: List[A]): List[A] = stream match {
15       case Cons(head, tail) => go(tail(), head() :: acc)
16       case _ => acc
17     }
18     go(this, List()).reverse
19   }
20 }
21 
22 case object Empty extends Stream[Nothing]
23 case class Cons[+A](head: () => A, tail: () => Stream[A]) extends Stream[A]
24 
~
~
~
~