Skip to content

Syntax proposal: call it forZip #2

@krux02

Description

@krux02

There is one big reason why I don't like the forEach, and that is my Scala background.

val seq1 = Seq(1,2,3)
val seq2 = Seq(4,5,6)
for( a <- seq1, b <- seq2 ) {
    println(a,b)
}

val seq1 = Seq(1,2,3)
val seq2 = Seq(4,5,6)
is compiled to:

seq1.forEach(a => seq2.forEach(b => println(a,b))

This is basically just a nested loop with λ-expressions as the body. Zip would be the following:

val seq1 = Seq(1,2,3)
val seq2 = Seq(4,5,6)

for( (a,b) <- zip(seq1, seq2) ) {
    println(a,b)
}

I don't say you should take over or try to mimic the Scala syntax, but I think you should take over the names. Please call it to something that has both for and zip in the name. forEach has already a very specific meaning in my head, and it is not what you are doing with forEach. Also c++ has already std::foreach and it means the same as in scala (it's just useless in c++, but that is an opinion and a different topic). And I don't think it is a bad idea to adopt to scala naming conventions (I personally really liked them for the most part)

(please don't kill me if the scala snippents don't compile, I did not program scala for years, and I have no compiler on this machine)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions