I am trying to split Scala list like List(1,2,3,4) into pairs (1,2) (2,3) (3,4), what\'s a simple way to do this?
List(1,2,3,4)
(1,2) (2,3) (3,4)
To produce a list of pairs (i.e. tuples) try this
List(1,2,3,4,5).sliding(2).collect{case List(a,b) => (a,b)}.toList