Title: Chunk Sequence In Equal Sized Groups
Slug: chuck_sequence_into_equal_sized_groups
Summary: Chunk Sequence In Equal Sized Groups Using Scala.
Date: 2017-01-03 12:00
Category: Scala
Tags: Basics
Authors: Chris Albon
If you want to learn more, check out Scala Cookbook and Programming in Scala.
In [7]:
// Create an array that contains arrays with first and last names
val ages = List(42,25,28,38,58,63,23,458,2569,584,25,25,878)
In [8]:
// Slide over sequence, create a list of two elements, then take two steps
ages.sliding(2,2).toArray
Out[8]:
In [9]:
// Slide over sequence, create a list of two elements, then take one step
ages.sliding(2,1).toArray
Out[9]: