coerceAtMost method

T coerceAtMost(
  1. T maximumValue
)

Ensures that this value is not greater than the specified maximumValue.

Return this value if it's less than or equal to the maximumValue or the maximumValue otherwise.

print(10.coerceAtMost(5)) // 5
print(10.coerceAtMost(20)) // 10

Implementation

T coerceAtMost(T maximumValue) => this > maximumValue ? maximumValue : this;