Logo

Programming-Idioms

History of Idiom 163 > diff from v12 to v13

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

Version 12

2019-02-02, 04:51:38

Version 13

2019-02-02, 04:53:22

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)})")