Programming-Idioms

History of Idiom 163 > diff from v12 to v13

Edit summary for version 13 :
[Scala] Make it a little cleaner, like the Rust one

Version 12

Version 13

Idiom #163 Print list elements by group of 2

Print all the list elements, two by two, assuming list length is even.

Idiom #163 Print list elements by group of 2

Print all the list elements, two by two, assuming list length is even.

Code
list.grouped(2).foreach(p => println(s"(${p(0)}, ${p(1)})"))
Code
for (pair <- list.grouped(2))
  println(s"(${pair(0)}, ${pair(1)})")