Skip to content

Commit 6a05feb

Browse files
author
Javier de Silóniz Sandino
committed
Added language review fixes
1 parent 6b0d257 commit 6a05feb

File tree

5 files changed

+72
-73
lines changed

5 files changed

+72
-73
lines changed

src/main/scala/fpinscalalib/ErrorHandlingSection.scala

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
2121
* of using error codes, we introduce a new generic type for these “possibly defined values” and use higher-order
2222
* functions to encapsulate common patterns of handling and propagating errors.
2323
*
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:
2626
*
2727
* {{{
2828
* sealed trait Option[+A]
@@ -33,8 +33,8 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
3333
* Option has two cases: it can be defined, in which case it will be a `Some`, or it can be undefined, in which case
3434
* it will be `None`.
3535
*
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:
3838
*/
3939

4040
def optionMeanAssert(res0: Option[Double]): Unit = {
@@ -89,7 +89,7 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
8989
* def flatMap[B](f: A => Option[B]): Option[B] = map(f) getOrElse None
9090
* }}}
9191
*
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
9393
* managing each employee, if applicable:
9494
*/
9595

@@ -102,7 +102,7 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
102102
}
103103

104104
/**
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
106106
* return the default value provided by the caller. The `B >: A` in the declaration tells that the `B` type parameter
107107
* must be a supertype of `A`. Furthermore, `default : => B` indicates that the argument is of type B, but won’t be
108108
* evaluated until it’s needed by the function.
@@ -140,7 +140,7 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
140140
* }
141141
* }}}
142142
*
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:
144144
*/
145145

146146
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
189189
*/
190190

191191
/**
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
193193
* of `Option`s into one `Option` containing a list of all the `Some` values in the original list. If the original
194194
* list contains `None` even once, the result of the function should be `None`. Otherwise the result should be a `Some`
195195
* with a list of all the values:
@@ -201,7 +201,7 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
201201
* }
202202
* }}}
203203
*
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:
205205
*/
206206

207207
def optionSequenceAssert(res0: Some[List[Int]], res1: Option[List[Int]]): Unit = {
@@ -268,7 +268,7 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
268268
* case class Right[+A](value: A) extends Either[Nothing, A]
269269
* }}}
270270
*
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
272272
* we use it to indicate success or failure, by convention the `Right` constructor is reserved for the success case
273273
* (a pun on “right,” meaning correct), and `Left` is used for failure.
274274
*
@@ -297,7 +297,7 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
297297
* }
298298
* }}}
299299
*
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
301301
* possible errors that may arise, as the chain will stop if any error occurs. Let's try it out, by improving the
302302
* employee lookup function we implemented before, to use `Either` instead of `Option`. Try to use `map` on the
303303
* `Either` type to obtain the department of each employee:
@@ -318,9 +318,9 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
318318
}
319319

320320
/**
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:
324324
*/
325325

326326
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
347347
* }
348348
* }}}
349349
*
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"
351351
* manager. We can provide that logic with `orElse`:
352352
*/
353353

@@ -376,7 +376,7 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
376376
* } yield f(a,b1)
377377
* }}}
378378
*
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
380380
* hold a list of errors:
381381
*
382382
* {{{
@@ -414,7 +414,7 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
414414
* def sequence[E,A](es: List[Either[E,A]]): Either[E,List[A]] = traverse(es)(x => x)
415415
* }}}
416416
*
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`:
418418
*/
419419

420420
def eitherTraverseAssert(res0: Right[List[Employee]], res1: Left[String]): Unit = {
@@ -426,8 +426,8 @@ object ErrorHandlingSection extends FlatSpec with Matchers with org.scalaexercis
426426
}
427427

428428
/**
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:
431431
*/
432432

433433
def eitherSequenceAssert(res0: Right[List[Employee]], res1: Left[String]): Unit = {

src/main/scala/fpinscalalib/FunctionalDataStructuresSection.scala

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object FunctionalDataStructuresSection extends FlatSpec with Matchers with org.s
1313
/**
1414
* = Singly linked lists =
1515
*
16-
* First let's examine what's probably the most ubiquitous functional data structure, the singly linked list. The
16+
* Let's examine what's probably the most ubiquitous functional data structure, the singly-linked list to start. The
1717
* definition here is identical in spirit to (though simpler than) the `List` data type defined in Scala's standard
1818
* library.
1919
*
@@ -40,7 +40,7 @@ object FunctionalDataStructuresSection extends FlatSpec with Matchers with org.s
4040
* }}}
4141
*
4242
* The definition of the data type begins with the keywords `sealed trait`. In general, we introduce a data type with
43-
* the `trait` keyword. A `trait` is a an abstract interface that may optionally contain implementations of some
43+
* the `trait` keyword. A `trait` is an abstract interface that may optionally contain implementations of some
4444
* methods. There are two such implementations, or data constructors, of `List`, to represent the two possible forms a
4545
* `List` can take. A `List` can be empty (denoted by the data constructor `Nil`), or it can be nonempty, denoted by
4646
* the data constructor `Cons` (traditionally short for `construct`). A nonempty list consists of an initial element,
@@ -53,7 +53,7 @@ object FunctionalDataStructuresSection extends FlatSpec with Matchers with org.s
5353
* `List`. Both definitions make use of pattern matching.
5454
*
5555
* As you might expect, the `sum` function states that the sum of an empty list is 0, and the sum of a nonempty list
56-
* is the first element, `x`, plus the sum of the remaining elements, `xs`. Likewise the `product` definition states
56+
* is the first element, `x`, plus the sum of the remaining elements, `xs`. Likewise, the `product` definition states
5757
* that the product of an empty list is `1.0`, the product of any other nonempty list starting with `0.0` is `0.0`,
5858
* and the product of any other nonempty list is the first element multiplied by the product of the remaining elements.
5959
*
@@ -111,7 +111,7 @@ object FunctionalDataStructuresSection extends FlatSpec with Matchers with org.s
111111
* }
112112
* }}}
113113
*
114-
* Taking a look at its implementation, check its behaviour on the following cases:
114+
* After taking a look at its implementation, check out its behaviour on the following cases:
115115
*/
116116

117117
def listTakeAssert(res0: List[Int], res1: List[Int]) {
@@ -121,7 +121,7 @@ object FunctionalDataStructuresSection extends FlatSpec with Matchers with org.s
121121

122122
/**
123123
* Using the same idea, we can implement the function `setHead` for replacing the first element of a List with a
124-
* a different value:
124+
* different value:
125125
*
126126
* {{{
127127
* def setHead[A](l: List[A], h: A): List[A] = l match {
@@ -173,7 +173,7 @@ object FunctionalDataStructuresSection extends FlatSpec with Matchers with org.s
173173
* }
174174
* }}}
175175
*
176-
* Check how it works with the following examples:
176+
* See how it works with the following examples:
177177
*/
178178

179179
def listDropWhileAssert(res0: List[Int], res1: List[Int], res2: List[Int], res3: List[Int]) {
@@ -185,7 +185,7 @@ object FunctionalDataStructuresSection extends FlatSpec with Matchers with org.s
185185

186186
/**
187187
* In the same fashion, let's implement another function `init` that returns a `List` consisting of all but the last
188-
* element of a `List`. Take a note that this function can't be implemented in constant time like `tail`.
188+
* element of a `List`. It should be noted that this function cannot be implemented in constant time like `tail`.
189189
*
190190
* {{{
191191
* def init[A](l: List[A]): List[A] =
@@ -207,8 +207,8 @@ object FunctionalDataStructuresSection extends FlatSpec with Matchers with org.s
207207
/**
208208
* = Recursion over lists and generalizing to higher-order functions =
209209
*
210-
* Let’s look again at the implementations of sum and product. We’ve simplified the product implementation slightly,
211-
* so as not to include the “short-circuiting” logic of checking for 0.0:
210+
* Once again, let’s take a look at the implementations of `sum` and `product`. We’ve simplified the product
211+
* implementation slightly, so as not to include the “short-circuiting” logic of checking for 0.0:
212212
*
213213
* {{{
214214
* def sum(ints: List[Int]): Int = ints match {
@@ -227,7 +227,7 @@ object FunctionalDataStructuresSection extends FlatSpec with Matchers with org.s
227227
* of sum, 1.0 in the case of product), and the operation to combine results (+ in the case of sum, * in the case of
228228
* product).
229229
*
230-
* We can do better by generalizing those functions, by implementing a `foldRight`. This function will take as
230+
* We can improve things by generalizing those functions, by implementing a `foldRight`. This function will take on as
231231
* arguments the value to return in the case of the empty list, and the function to add an element to the result in
232232
* the case of a nonempty list:
233233
*
@@ -262,8 +262,8 @@ object FunctionalDataStructuresSection extends FlatSpec with Matchers with org.s
262262
}
263263

264264
/**
265-
* Now that we know how `foldRight` works, try to think what happens when you pass `Nil` and `Cons` themselves to
266-
* `foldRight`.
265+
* Now that we know how `foldRight` works, try to think about what happens when you pass `Nil` and `Cons` themselves
266+
* to `foldRight`.
267267
*/
268268

269269
def listFoldRightNilConsAssert(res0: List[Int]) {
@@ -414,8 +414,8 @@ object FunctionalDataStructuresSection extends FlatSpec with Matchers with org.s
414414
*/
415415

416416
/**
417-
* Let's apply the same principle as in `map` to remove elements from a list, starting with a function to remove all
418-
* odd numbers from a List[Int]:
417+
* Let's apply the same principle as we use in `map` to remove elements from a list, starting with a function to
418+
* remove all odd numbers from a List[Int]:
419419
*/
420420
def listRemoveOdds(res0: Int, res1: Int): Unit = {
421421
def removeOdds(l: List[Int]): List[Int] =
@@ -494,7 +494,7 @@ object FunctionalDataStructuresSection extends FlatSpec with Matchers with org.s
494494
}
495495

496496
/**
497-
* As a final example to work with lists, let's implement a `hasSubsequence` function for checking whether a `List`
497+
* As a final example for working with lists, let's implement a `hasSubsequence` function for checking whether a `List`
498498
* contains another `List` as a subsequence. For instance, `List(1, 2, 3, 4)` would have `List(1, 2)`, `List(2, 3)`
499499
* and `List(4)` as subsequences, among others:
500500
*
@@ -514,7 +514,7 @@ object FunctionalDataStructuresSection extends FlatSpec with Matchers with org.s
514514
* }
515515
* }}}
516516
*
517-
* Take a deep look at the implementation of this function, and then try it out in the next exercise:
517+
* Take a thorough look at the implementation of this function, and then try it out in the next exercise:
518518
*/
519519

520520
def listHasSubsequenceAssert(res0: Boolean, res1: Boolean, res2: Boolean): Unit = {

src/main/scala/fpinscalalib/FunctionalStateSection.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ object FunctionalStateSection extends FlatSpec with Matchers with org.scalaexerc
7474
*
7575
* = Making stateful APIs pure =
7676
*
77-
* This problem of making seemingly stateful APIs pure comes up frequently, and we can always deal with it in this
78-
* same way. For instance:
77+
* Making seemingly stateful APIs pure is a problem that comes up frequently. We can always handle this in the same
78+
* way, for instance:
7979
*
8080
* {{{
8181
* class Foo {
@@ -324,8 +324,8 @@ object FunctionalStateSection extends FlatSpec with Matchers with org.scalaexerc
324324
}
325325

326326
/**
327-
* We can also rewrite `map` and `map2` in terms of `flatMap`. The fact that this is possible is what we’re referring
328-
* to when we say that `flatMap` is more powerful than `map` and `map2`.
327+
* We can also rewrite `map` and `map2` in terms of `flatMap`. The fact that this is possible is why we say that
328+
* `flatMap` is more powerful than `map` and `map2`.
329329
*
330330
* {{{
331331
* def _map[A,B](s: Rand[A])(f: A => B): Rand[B] =
@@ -334,8 +334,8 @@ object FunctionalStateSection extends FlatSpec with Matchers with org.scalaexerc
334334
* flatMap(ra)(a => map(rb)(b => f(a, b)))
335335
* }}}
336336
*
337-
* As a final example, let's revisit our previously written functions to implement a function that roll a six-sided
338-
* die:
337+
* As a final example, lets revisit the functions we previously wrote and implement a function that will roll a
338+
* six-sided die:
339339
*/
340340

341341
def randomRollDie(res0: Int): Unit = {
@@ -370,8 +370,8 @@ object FunctionalStateSection extends FlatSpec with Matchers with org.scalaexerc
370370
* case class State[S,+A](run: S => (A,S))
371371
* }}}
372372
*
373-
* Now we have a single, general-purpose type, and using this type we can write general-purpose functions for
374-
* capturing common patterns of stateful programs. We can now just make `Rand` a type alias for `State`:
373+
* Now we have a single, general-purpose type and can use it to write general-purpose functions for capturing common
374+
* patterns of stateful programs. We can now make `Rand` a type alias for `State`:
375375
*
376376
* {{{
377377
* type Rand[A] = State[RNG, A]
@@ -411,7 +411,7 @@ object FunctionalStateSection extends FlatSpec with Matchers with org.scalaexerc
411411
* The rules of the machine are as follows:
412412
*
413413
* - Inserting a coin into a locked machine will cause it to unlock if there’s any candy left.
414-
* - Turning the knob on an unlocked machine will cause it to dispense candy and become locked.
414+
* - Turning the knob on an unlocked machine will cause it to dispense candy and then lock.
415415
* - Turning the knob on a locked machine or inserting a coin into an unlocked machine does nothing.
416416
* - A machine that’s out of candy ignores all inputs.
417417
*

0 commit comments

Comments
 (0)