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

improve description about enumerator in for-comprehensions #2992

Closed
wants to merge 1 commit into from

Conversation

laglangyue
Copy link

@laglangyue laglangyue commented Mar 4, 2024

Student of Scala may have some doubts when learning for-enumerators, and may not understand the execution order of if enumerator. They may think that if is similar to match grammer, they think if i + j == v will execute before j <-....
look at this example

    val a = Array(1, 2, 3)
    val value = for
      i <- 0 to 5;
      j = a(i) if i % 2 == 0
     yield (j)

Actually, it should be

    val a = Array(1, 2, 3)
    val value = for
      i <- 0 to 5 if i % 2 == 0
      j = a(i) 
     yield (j)

@bishabosha
Copy link
Member

@scala/docs-zh

@laglangyue laglangyue marked this pull request as draft March 4, 2024 13:24
@laglangyue
Copy link
Author

sorry,I check this PR again,My friend doesn't read the documentation very well.
This section has explained very clearly how if works in for-comprehensions.
image

@laglangyue laglangyue closed this Mar 5, 2024
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

Successfully merging this pull request may close these issues.

3 participants