exercises-stdlib icon indicating copy to clipboard operation
exercises-stdlib copied to clipboard

"For Expressions" section needs a few simple examples to start off with

Open rzats opened this issue 9 years ago • 1 comments

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 for loop:
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) { ... }

rzats avatar Dec 31 '16 21:12 rzats

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

AlphaJuliettOmega avatar Aug 12 '20 14:08 AlphaJuliettOmega