@@ -21,8 +21,8 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
21
21
* of using error codes, we introduce a new generic type for these “possibly defined values” and use higher-order
22
22
* functions to encapsulate common patterns of handling and propagating errors.
23
23
*
24
- * We introduce a new type, `Option`. As with the previously explored `List`, this type also exists in the Scala
25
- * standard library, but we're re-creating it here for pedagogical purposes:
24
+ * We're going to introduce a new type, `Option`. As with the previously explored `List`, this type also exists in
25
+ * the Scala standard library, but we're re-creating it here for pedagogical purposes:
26
26
*
27
27
* {{{
28
28
* sealed trait Option[+A]
@@ -33,8 +33,8 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
33
33
* Option has two cases: it can be defined, in which case it will be a `Some`, or it can be undefined, in which case
34
34
* it will be `None`.
35
35
*
36
- * Let's consider an example to use our new type. We're defining a function `mean` that computes the mean of a list,
37
- * which is undefined if the list is empty:
36
+ * Let's consider an example on how we can use our new type. We're defining a function `mean` that computes the mean
37
+ * of a list, which is undefined if the list is empty:
38
38
*/
39
39
40
40
def optionMeanAssert (res0 : Option [Double ]): Unit = {
@@ -89,7 +89,7 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
89
89
* def flatMap[B](f: A => Option[B]): Option[B] = map(f) getOrElse None
90
90
* }}}
91
91
*
92
- * By using `flatMap` we can chain operations that also can fail, as in the following example. Try to find out who is
92
+ * By using `flatMap` we can chain operations that can also fail, as in the following example. Try to find out who is
93
93
* managing each employee, if applicable:
94
94
*/
95
95
@@ -102,7 +102,7 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
102
102
}
103
103
104
104
/**
105
- * The function `getOrElse` used above, tries to get the value contained in the Option, but if it's a `None` will
105
+ * The function `getOrElse` used above, tries to get the value contained in the Option, but if it's a `None`, it will
106
106
* return the default value provided by the caller. The `B >: A` in the declaration tells that the `B` type parameter
107
107
* must be a supertype of `A`. Furthermore, `default : => B` indicates that the argument is of type B, but won’t be
108
108
* evaluated until it’s needed by the function.
@@ -140,7 +140,7 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
140
140
* }
141
141
* }}}
142
142
*
143
- * Try it out to discard those employees who belong to the IT department:
143
+ * Test it out by discarding those employees who belong to the IT department:
144
144
*/
145
145
146
146
def optionFilterAssert (res0 : Some [Employee ], res1 : Option [Employee ], res2 : Option [Employee ]): Unit = {
@@ -189,7 +189,7 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
189
189
*/
190
190
191
191
/**
192
- * Let's continue looking at a few other similar cases. For instance, the `sequence` function, which combines a list
192
+ * Let's continue by looking at a few other similar cases. For instance, the `sequence` function, which combines a list
193
193
* of `Option`s into one `Option` containing a list of all the `Some` values in the original list. If the original
194
194
* list contains `None` even once, the result of the function should be `None`. Otherwise the result should be a `Some`
195
195
* with a list of all the values:
@@ -201,7 +201,7 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
201
201
* }
202
202
* }}}
203
203
*
204
- * After taking a look at the implementation, check how it works in the following exercise:
204
+ * After taking a look at the implementation, see how it works in the following exercise:
205
205
*/
206
206
207
207
def optionSequenceAssert (res0 : Some [List [Int ]], res1 : Option [List [Int ]]): Unit = {
@@ -268,7 +268,7 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
268
268
* case class Right[+A](value: A) extends Either[Nothing, A]
269
269
* }}}
270
270
*
271
- * `Either` has only two cases, just like `Option`. The essential difference is that both cases carry a value. When
271
+ * `Either` only has two cases, just like `Option`. The essential difference is that both cases carry a value. When
272
272
* we use it to indicate success or failure, by convention the `Right` constructor is reserved for the success case
273
273
* (a pun on “right,” meaning correct), and `Left` is used for failure.
274
274
*
@@ -297,7 +297,7 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
297
297
* }
298
298
* }}}
299
299
*
300
- * In the same fashion as `Option`, `map` allow us to chain operations on an `Either` without worrying about the
300
+ * In the same fashion as `Option`, `map` allows us to chain operations on an `Either` without worrying about the
301
301
* possible errors that may arise, as the chain will stop if any error occurs. Let's try it out, by improving the
302
302
* employee lookup function we implemented before, to use `Either` instead of `Option`. Try to use `map` on the
303
303
* `Either` type to obtain the department of each employee:
@@ -318,9 +318,9 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
318
318
}
319
319
320
320
/**
321
- * `flatMap` behaves the same in `Either` as in `Option`, allowing us to chain operations that may also fail. Use it
322
- * to try to obtain the managers from each employee. Note that when calling our `getManager` function, we can find
323
- * two different errors in its execution:
321
+ * `flatMap` behaves the same in `Either` as it does in `Option`, allowing us to chain operations that may also fail.
322
+ * Use it to try to obtain the managers from each employee. Note that when calling our `getManager` function, we can
323
+ * find two different errors in its execution:
324
324
*/
325
325
326
326
def eitherFlatMapAssert (res0 : Right [String ], res1 : Left [String ], res2 : Left [String ]): Unit = {
@@ -347,7 +347,7 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
347
347
* }
348
348
* }}}
349
349
*
350
- * Let's check how it behaves. Let's assume that everyone inside our company ends up responding to a "Mr. CEO"
350
+ * Let's check out how it behaves. Let's assume that everyone inside our company ends up responding to a "Mr. CEO"
351
351
* manager. We can provide that logic with `orElse`:
352
352
*/
353
353
@@ -376,7 +376,7 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
376
376
* } yield f(a,b1)
377
377
* }}}
378
378
*
379
- * In this implementation, we can't report errors on both sides. To do that, we would need a new data type that could
379
+ * In this implementation, we can't report errors on both sides. To do that, we would need a new data type that can
380
380
* hold a list of errors:
381
381
*
382
382
* {{{
@@ -414,7 +414,7 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
414
414
* def sequence[E,A](es: List[Either[E,A]]): Either[E,List[A]] = traverse(es)(x => x)
415
415
* }}}
416
416
*
417
- * We can try to lookup through a list of employee names to obtain a list of `Employees`:
417
+ * We can attempt to obtain a record of employees names by looking up a list of `Employees`:
418
418
*/
419
419
420
420
def eitherTraverseAssert (res0 : Right [List [Employee ]], res1 : Left [String ]): Unit = {
@@ -426,8 +426,8 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
426
426
}
427
427
428
428
/**
429
- * As for `sequence`, we can create a `List` of employees we looked up by using the `lookupByNameViaEither`, and
430
- * find out if we were looking for some missing person:
429
+ * As for `sequence`, we can create a `List` of the employees we looked up by using the `lookupByNameViaEither`, and
430
+ * find out if we were looking for a missing person:
431
431
*/
432
432
433
433
def eitherSequenceAssert (res0 : Right [List [Employee ]], res1 : Left [String ]): Unit = {
0 commit comments