toPairs method

List<Pair<T, T>> toPairs()

Returns consecutive pairs of elements.

[1,2,3,4].toPairs() // [(1,2),(2,3),(3,4)]

Implementation

List<Pair<T, T>> toPairs() {
  if (length < 2) return [];
  return List.generate(length - 1, (i) => Pair(this[i], this[i + 1]));
}