Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rzats opened this issue Dec 31, 2016 · 1 comment
Open

Comments

@rzats
Copy link
Contributor

rzats commented Dec 31, 2016

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) { ... }
@AlphaJuliettOmega
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants