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?
I am trying to split Scala list like List(1,2,3,4) into pairs (1,2) (2,3) (3,4)
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As the docs say,
zipSo
List('a,'b,'c,'d)zipped withList('x,'y,'z)isList(('a,'x), ('b,'y), ('c,'z))with the final'dof the first one ignored.From your example, the
tailofList(1,2,3,4)isList(2,3,4)so you can see how these zip together in pairs.