What is the most elegant way using the standard library to group consecutive paris of elements into 2-tuples? I’m not sure what type of data structure the elements are given in, so hopefully the solution could be fairly general, working on arrays, lists, sequences, etc.
Something like the following
Of course one element might be left over so it would have to be handled specially, e.g., return a pair consisting of the list of pairs and an
Option of the remaining element.
I can easily do this with a tail recursive function given that the input is a
List or an
Array, but can it be done as some combination of drop/fold/zip/scan for example?