coerceAtMost code example

Example: coerceAtMost

//Ensures that this value is not greater than the specified maximumValue
//coerceAtMost is recommended instead of Math.Min or Math.Max

//Int Example
println(10.coerceAtMost(5)) // prints 5
println(10.coerceAtMost(20)) // prints 10
println(10.coerceAtMost(30)) // prints 10

//enum example
println(DayOfWeek.FRIDAY.coerceAtMost(DayOfWeek.SATURDAY)) // FRIDAY
println(DayOfWeek.FRIDAY.coerceAtMost(DayOfWeek.WEDNESDAY)) // WEDNESDAY

Tags:

Cpp Example