clamp method

T clamp(
  1. T low,
  2. T high
)

Clamps this Comparable to be within the range [low, high].

Implementation

T clamp(T low, T high) =>
    (this < low) ? low : ((this > high) ? high : (this as T));