Skip to content

Commit d175b70

Browse files
author
Rafa Paradela
committed
Merge pull request scala-exercises#44 from 47deg/vejeta-patch-partialfunctions.json
Update partialfunctions.json
2 parents d077140 + c082e3d commit d175b70

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

app/json/partialfunctions.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"modules": [
44
{
55
"preparagraph": "A partial function is a `trait` that when implemented can be used as building blocks to determine a solution. The trait PartialFunction requires that the method `isDefinedAt` and `apply` be implemented.",
6-
"code": "val doubleEvens: PartialFunction[Int, Int] = new PartialFunction[Int, Int] {\n //States that this partial function will take on the task\n def isDefinedAt(x: Int) = x % 2 == 0\n\n //What we do if this does partial function matches\n def apply(v1: Int) = v1 * 2\n}\n\nval tripleOdds: PartialFunction[Int, Int] = new PartialFunction[Int, Int] {\n def isDefinedAt(x: Int) = x % 2 != 0\n\n def apply(v1: Int) = v1 * 3\n}\n\nval whatToDo = doubleEvens orElse tripleOdds //Here we chain the partial functions together\n\nwhatToDo(3) should be(__)\nwhatToDo(4) should be(__)",
6+
"code": "val doubleEvens: PartialFunction[Int, Int] = new PartialFunction[Int, Int] {\n //States that this partial function will take on the task\n def isDefinedAt(x: Int) = x % 2 == 0\n\n //What we do if this partial function matches\n def apply(v1: Int) = v1 * 2\n}\n\nval tripleOdds: PartialFunction[Int, Int] = new PartialFunction[Int, Int] {\n def isDefinedAt(x: Int) = x % 2 != 0\n\n def apply(v1: Int) = v1 * 3\n}\n\nval whatToDo = doubleEvens orElse tripleOdds //Here we chain the partial functions together\n\nwhatToDo(3) should be(__)\nwhatToDo(4) should be(__)",
77
"solutions": [
88
"9",
99
"8"
@@ -12,7 +12,7 @@
1212
},
1313
{
1414
"preparagraph": "Case statements are a quick way to create partial functions. When you create a case statement, the apply and `isDefinedAt` is created for you.",
15-
"code": "//The case statements are called case statements with guards\nval doubleEvens: PartialFunction[Int, Int] = {\n case x: Int if (x % 2) == 0 => x * 2\n}\nval tripleOdds: PartialFunction[Int, Int] = {\n case x: Int if (x % 2) != 0 => x * 3\n}\n\nval whatToDo = doubleEvens orElse tripleOdds //Here we chain the partial functions together\nwhatToDo(3) should be(__)\nwhatToDo(4) should be(__)",
15+
"code": "//These case statements are called case statements with guards\nval doubleEvens: PartialFunction[Int, Int] = {\n case x: Int if (x % 2) == 0 => x * 2\n}\nval tripleOdds: PartialFunction[Int, Int] = {\n case x: Int if (x % 2) != 0 => x * 3\n}\n\nval whatToDo = doubleEvens orElse tripleOdds //Here we chain the partial functions together\nwhatToDo(3) should be(__)\nwhatToDo(4) should be(__)",
1616
"solutions": [
1717
"9",
1818
"8"
@@ -38,4 +38,4 @@
3838
"postparagraph": ""
3939
}
4040
]
41-
}
41+
}

0 commit comments

Comments
 (0)