Этого можно достичь с помощью grouped(size: Int)
.
Пример:
val l = List(1,2,3,4,5,6,7,8,9,10)
println(l.grouped(2).toSeq) // --> Stream(List(1, 2), ?)
println(l.grouped(2).toList) // --> List(List(1, 2), List(3, 4), List(5, 6), List(7, 8), List(9, 10))
С IterableLike
( ScalaDoc ):
/** Partitions elements in fixed size ${coll}s.
* @see [[scala.collection.Iterator]], method `grouped`
*
* @param size the number of elements per group
* @return An iterator producing ${coll}s of size `size`, except the
* last will be less than size `size` if the elements don't divide evenly.
*/
def grouped(size: Int): Iterator[Repr] = ...