Skip to content

Commit 67bb3fd

Browse files
author
Rafa Paradela
committed
Merge pull request scala-exercises#46 from hasumedic/traversables-typos
Traversables typos
2 parents d67593f + 97b4c6b commit 67bb3fd

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

app/json/traversables.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@
227227
"postparagraph": ""
228228
},
229229
{
230-
"preparagraph": "`headOption` will return the first element as an *Option* of an order collection, or some random element if order is not defined. If a first element is not available, then *None* is returned.",
230+
"preparagraph": "`headOption` will return the first element as an *Option* of an ordered collection, or some random element if order is not defined. If a first element is not available, then *None* is returned.",
231231
"code": "val list = List(10, 19, 45, 1, 22)\nlist.headOption should be(Some(__))\n\nval list2 = List()\nlist2.headOption should be(__)",
232232
"solutions": [
233233
"10",
@@ -244,7 +244,7 @@
244244
"postparagraph": ""
245245
},
246246
{
247-
"preparagraph": "`lastOption` will return the first element as an *Option* of an order collection, or some random element if order is not defined. If a first element is not available, then `None` is returned:",
247+
"preparagraph": "`lastOption` will return the first element as an *Option* of an ordered collection, or some random element if order is not defined. If a first element is not available, then `None` is returned:",
248248
"code": "val list = List(10, 19, 45, 1, 22)\nlist.lastOption should be(Some(__))\n\nval list2 = List()\nlist2.lastOption should be(__)",
249249
"solutions": [
250250
"22",
@@ -323,7 +323,7 @@
323323
"postparagraph": ""
324324
},
325325
{
326-
"preparagraph": "`takeWhile` will continually accumulate elements until a predicate is no longer satisfied. In this exercise, *TreeSet* is *Traversable*. *TreeSet* also is also sorted.",
326+
"preparagraph": "`takeWhile` will continually accumulate elements until a predicate is no longer satisfied.",
327327
"code": "val list = List(87, 44, 5, 4, 200, 10, 39, 100)\nlist.takeWhile(_ < 100) should be(List(__, __, __, __))",
328328
"solutions": [
329329
"87",
@@ -334,7 +334,7 @@
334334
"postparagraph": ""
335335
},
336336
{
337-
"preparagraph": "`dropWhile` will continually drop elements until a predicate is no longer satisfied. Again, *TreeSet* is *Traversable*. *TreeSet* also is also sorted.",
337+
"preparagraph": "`dropWhile` will continually drop elements until a predicate is no longer satisfied.",
338338
"code": "val list = List(87, 44, 5, 4, 200, 10, 39, 100)\nlist.dropWhile(_ < 100) should be(List(__, __, __, __))",
339339
"solutions": [
340340
"200",
@@ -397,7 +397,7 @@
397397
"postparagraph": ""
398398
},
399399
{
400-
"preparagraph": "`partition` will split a *Traversable* according to predicate, return a 2 product *Tuple*. The left side are the elements satisfied by the predicate, the right side is `not`. *Array* is *Traversable*, partition is also defined as `(xs filter p, xs filterNot p)`",
400+
"preparagraph": "`partition` will split a *Traversable* according to predicate, returning a 2 product *Tuple*. The left hand side contains the elements satisfied by the predicate whereas the right hand side contains those that `don't`. *Array* is *Traversable*, partition is also defined as `(xs filter p, xs filterNot p)`",
401401
"code": "val array = Array(87, 44, 5, 4, 200, 10, 39, 100)\nval result = array partition (_ < 100)\nresult._1 should be(Array(__, __, __, __, __, __))\nresult._2 should be(Array(__, __))",
402402
"solutions": [
403403
"87",
@@ -412,7 +412,7 @@
412412
"postparagraph": ""
413413
},
414414
{
415-
"preparagraph": "`groupBy` will categorize a *Traversable* according to function, and return a map with the results. This exercise uses *Partial Function* chaining.",
415+
"preparagraph": "`groupBy` will categorize a *Traversable* according to a given function, and return a map with the results. This exercise uses *Partial Function* chaining.",
416416
"code": "val array = Array(87, 44, 5, 4, 200, 10, 39, 100)\n\nval oddAndSmallPartial: PartialFunction[Int, String] = {\n case x: Int if x % 2 != 0 && x < 100 => \"Odd and less than 100\"\n}\n\nval evenAndSmallPartial: PartialFunction[Int, String] = {\n case x: Int if x != 0 && x % 2 == 0 && x < 100 => \"Even and less than 100\"\n}\n\nval negativePartial: PartialFunction[Int, String] = {\n case x: Int if x < 0 => \"Negative Number\"\n}\n\nval largePartial: PartialFunction[Int, String] = {\n case x: Int if x > 99 => \"Large Number\"\n}\n\nval zeroPartial: PartialFunction[Int, String] = {\n case x: Int if x == 0 => \"Zero\"\n}\n\nval result = array groupBy {\n oddAndSmallPartial orElse\n evenAndSmallPartial orElse\n negativePartial orElse\n largePartial orElse\n zeroPartial\n}\n\n(result(\"Even and less than 100\") size) should be(__)\n(result(\"Large Number\") size) should be(__)",
417417
"solutions": [
418418
"3",
@@ -446,11 +446,12 @@
446446
},
447447
{
448448
"preparagraph": "`/:` or `foldLeft` will combine an operation starting with a seed and combining from the left. *Fold Left* is defined as (seed /: list), where seed is the initial value. Once the fold is established, you provide a function that takes two arguments. The first argument is the running total of the operation, and the second element is the next element of the list.\n\nGiven a `Traversable (x1, x2, x3, x4)`, an initial value of `init`, an operation `op`, `foldLeft` is defined as: `(((init op x1) op x2) op x3) op x4)`",
449-
"code": "val list = List(5, 4, 3, 2, 1)\nval result = (0 /: list) {\n (`running total`, `next element`) => `running total` - `next element`\n}\nresult should be(__)\n\nval result2 = list.foldLeft(0) {\n (`running total`, `next element`) => `running total` - `next element`\n}\nresult2 should be(__)\n\nval result3 = (0 /: list)(_ - _) //Short hand\nresult3 should be(__)\n\nval result4 = list.foldLeft(0)(_ - _)\nresult4 should be(-15)\n\n(((((0 - 5) - 4) - 3) - 2) - 1) should be(__)",
449+
"code": "val list = List(5, 4, 3, 2, 1)\nval result = (0 /: list) {\n (`running total`, `next element`) => `running total` - `next element`\n}\nresult should be(__)\n\nval result2 = list.foldLeft(0) {\n (`running total`, `next element`) => `running total` - `next element`\n}\nresult2 should be(__)\n\nval result3 = (0 /: list)(_ - _) //Short hand\nresult3 should be(__)\n\nval result4 = list.foldLeft(0)(_ - _)\nresult4 should be(__)\n\n(((((0 - 5) - 4) - 3) - 2) - 1) should be(__)",
450450
"solutions": [
451451
"-15",
452452
"-15",
453453
"-15",
454+
"-15",
454455
"-15"
455456
],
456457
"postparagraph": ""
@@ -576,4 +577,4 @@
576577
"postparagraph": ""
577578
}
578579
]
579-
}
580+
}

0 commit comments

Comments
 (0)