-
Notifications
You must be signed in to change notification settings - Fork 3
Description
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)