swap<T> static method
Returns a new list with the elements at i and j swapped.
Implementation
static List<T> swap<T>(Iterable<T> list, int i, int j) {
final source = list.toList();
if (i < 0 || i >= source.length) {
throw RangeError.index(i, source, 'i');
}
if (j < 0 || j >= source.length) {
throw RangeError.index(j, source, 'j');
}
final tmp = source[i];
source[i] = source[j];
source[j] = tmp;
return source;
}