swap method

  1. @Possible({RangeError})
void swap(
  1. int a,
  2. int b
)

Swaps the elements at the given indexes in-place.

['a', 'b', 'c']..swap(0, 2);  // ['c', 'b', 'a']

Implementation

@Possible({RangeError})
void swap(int a, int b) {
  RangeError.checkValidIndex(a, this, 'a');
  RangeError.checkValidIndex(b, this, 'b');

  final (a1, b1) = (this[a], this[b]);
  this[a] = b1;
  this[b] = a1;
}