File tree Expand file tree Collapse file tree 2 files changed +25
-27
lines changed
src/main/scala/scalatutorial/sections Expand file tree Collapse file tree 2 files changed +25
-27
lines changed Original file line number Diff line number Diff line change @@ -209,6 +209,18 @@ object LazyEvaluation extends ScalaTutorialSection {
209209 * lazy val x = expr
210210 * }}}
211211 *
212+ * = Lazy Vals and Streams =
213+ *
214+ * Using a lazy value for `tail`, `Stream.cons` can be implemented more efficiently:
215+ *
216+ * {{{
217+ * def cons[T](hd: T, tl: => Stream[T]) = new Stream[T] {
218+ * def head = hd
219+ * lazy val tail = tl
220+ * …
221+ * }
222+ * }}}
223+ *
212224 * == Exercise ==
213225 */
214226 def lazyVal (res0 : String ): Unit = {
@@ -223,18 +235,4 @@ object LazyEvaluation extends ScalaTutorialSection {
223235 builder.result() shouldBe res0
224236 }
225237
226- /**
227- * = Lazy Vals and Streams =
228- *
229- * Using a lazy value for `tail`, `Stream.cons` can be implemented more efficiently:
230- *
231- * {{{
232- * def cons[T](hd: T, tl: => Stream[T]) = new Stream[T] {
233- * def head = hd
234- * lazy val tail = tl
235- * …
236- * }
237- * }}}
238- */
239- def nothing (): Unit = ()
240238}
Original file line number Diff line number Diff line change @@ -141,19 +141,19 @@ object StructuringInformation extends ScalaTutorialSection {
141141 * the possible case of symbols is fixed. The compiler can leverage this
142142 * knowledge to warn us if we write code that does not handle ''all''
143143 * the cases:
144- */
145- def unexhaustive (): Unit = {
146- sealed trait Symbol
147- case class Note (name : String , duration : String , octave : Int ) extends Symbol
148- case class Rest (duration : String ) extends Symbol
149-
150- def nonExhaustiveDuration (symbol : Symbol ): String =
151- symbol match {
152- case Rest (duration) => duration
153- }
154- }
155-
156- /* *
144+ * {{{
145+ * def unexhaustive(): Unit = {
146+ * sealed trait Symbol
147+ * case class Note(name: String, duration: String, octave: Int) extends Symbol
148+ * case class Rest(duration: String) extends Symbol
149+ *
150+ * def nonExhaustiveDuration(symbol: Symbol): String =
151+ * symbol match {
152+ * case Rest(duration) => duration
153+ * }
154+ * }
155+ *}}}
156+ *
157157 * Try to run the above code to see how the compiler informs us that
158158 * we don’t handle all the cases in `nonExhaustiveDuration`.
159159 *
You can’t perform that action at this time.
0 commit comments