compareAndSwap method

Iterable<T> compareAndSwap(
  1. T other
)

Compares the current value with the other value and swaps them if necessary.

Returns a iterable containing the updated values in order.

Implementation

Iterable<T> compareAndSwap(T other) {
  T a = this;
  if (a.compareTo(other) > 0) {
    var temp = a;
    a = other;
    other = temp;
  }
  return [a, other];
}