Skip to content

Commit 23c987a

Browse files
author
Rafa Paradela
committed
Merge pull request scala-exercises#38 from d1egoaz/master
.flatten instead of .flatMap(x => x) in For Expressions
2 parents 197d3ac + 5f9a394 commit 23c987a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

app/json/forexpressions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
},
2929
{
3030
"preparagraph": "Using 'for' we can make more readable code",
31-
"code": "val nums = List(List(1), List(2), List(3), List(4), List(5))\n\nval result = for {\n numList <- nums\n num <- numList\n if(num%2 == 0)\n} yield(num)\n\nresult should be (__)\n\n// Which is the same as\n\nnums.flatMap(numList=>numList).filter(_%2==0) should be(result)\n",
31+
"code": "val nums = List(List(1), List(2), List(3), List(4), List(5))\n\nval result = for {\n numList <- nums\n num <- numList\n if(num%2 == 0)\n} yield(num)\n\nresult should be (__)\n\n// Which is the same as\nnums.flatMap(numList=>numList).filter(_%2==0) should be(result)\n\n// or the same as\nnums.flatten.filter(_%2==0) should be(result)\n",
3232
"solutions": [
3333
"List(2, 4)"
3434
],

0 commit comments

Comments
 (0)