exercises-stdlib
exercises-stdlib copied to clipboard
"For Expressions" section needs a few simple examples to start off with
The section jumps right into advanced examples (multiple generators and filters) without explaining the for syntax, generators or filters. It would be nice to start off with a few easier examples:
- Simple Java-style
forloop:
for (i <- 1 to 15) { ... }
- Simple Java-style '
foreach" loop:
for (element: Int <- someIntArray) { ... }
- A loop with a single generator and filter:
for (element: Int <- someIntArray if element % 2 == 0) { ... }
Agree, Java background here
val xValues = 1 to 4
val yValues = 1 to 2
val coordinates = for {
x <- xValues
y <- yValues
} yield (x, y)
coordinates(4) should be((, ))
This question about Nested For is very frustrating, I don't understand how to calculate what Coordinates(4) should be, or how to dissect it.
An introduction into simple examples could help