You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: app/json/traversables.json
+9-8Lines changed: 9 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -227,7 +227,7 @@
227
227
"postparagraph": ""
228
228
},
229
229
{
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.",
231
231
"code": "val list = List(10, 19, 45, 1, 22)\nlist.headOption should be(Some(__))\n\nval list2 = List()\nlist2.headOption should be(__)",
232
232
"solutions": [
233
233
"10",
@@ -244,7 +244,7 @@
244
244
"postparagraph": ""
245
245
},
246
246
{
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:",
248
248
"code": "val list = List(10, 19, 45, 1, 22)\nlist.lastOption should be(Some(__))\n\nval list2 = List()\nlist2.lastOption should be(__)",
249
249
"solutions": [
250
250
"22",
@@ -323,7 +323,7 @@
323
323
"postparagraph": ""
324
324
},
325
325
{
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.",
327
327
"code": "val list = List(87, 44, 5, 4, 200, 10, 39, 100)\nlist.takeWhile(_ < 100) should be(List(__, __, __, __))",
328
328
"solutions": [
329
329
"87",
@@ -334,7 +334,7 @@
334
334
"postparagraph": ""
335
335
},
336
336
{
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.",
338
338
"code": "val list = List(87, 44, 5, 4, 200, 10, 39, 100)\nlist.dropWhile(_ < 100) should be(List(__, __, __, __))",
339
339
"solutions": [
340
340
"200",
@@ -397,7 +397,7 @@
397
397
"postparagraph": ""
398
398
},
399
399
{
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)`",
401
401
"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(__, __))",
402
402
"solutions": [
403
403
"87",
@@ -412,7 +412,7 @@
412
412
"postparagraph": ""
413
413
},
414
414
{
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.",
416
416
"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(__)",
417
417
"solutions": [
418
418
"3",
@@ -446,11 +446,12 @@
446
446
},
447
447
{
448
448
"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)`",
0 commit comments