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 {
209
209
* lazy val x = expr
210
210
* }}}
211
211
*
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
+ *
212
224
* == Exercise ==
213
225
*/
214
226
def lazyVal (res0 : String ): Unit = {
@@ -223,18 +235,4 @@ object LazyEvaluation extends ScalaTutorialSection {
223
235
builder.result() shouldBe res0
224
236
}
225
237
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 = ()
240
238
}
Original file line number Diff line number Diff line change @@ -141,19 +141,19 @@ object StructuringInformation extends ScalaTutorialSection {
141
141
* the possible case of symbols is fixed. The compiler can leverage this
142
142
* knowledge to warn us if we write code that does not handle ''all''
143
143
* 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
+ *
157
157
* Try to run the above code to see how the compiler informs us that
158
158
* we don’t handle all the cases in `nonExhaustiveDuration`.
159
159
*
You can’t perform that action at this time.
0 commit comments