coerce At Least
Ensures that this value is not less than the specified minimumValue.
Return
this value if it's greater than or equal to the minimumValue or the minimumValue otherwise.
Samples
import samples.*
import java.time.DayOfWeek
import kotlin.test.assertFailsWith
fun main() {
//sampleStart
assertPrints(DayOfWeek.WEDNESDAY.coerceAtLeast(DayOfWeek.MONDAY), "WEDNESDAY")
assertPrints(DayOfWeek.WEDNESDAY.coerceAtLeast(DayOfWeek.FRIDAY), "FRIDAY")
//sampleEnd
}
Ensures that this value is not less than the specified minimumValue.
Return
this value if it's greater than or equal to the minimumValue or the minimumValue otherwise.
Samples
import samples.*
import java.time.DayOfWeek
import kotlin.test.assertFailsWith
fun main() {
//sampleStart
assertPrints(10.coerceAtLeast(5), "10")
assertPrints(10.coerceAtLeast(20), "20")
//sampleEnd
}
Ensures that this value is not less than the specified minimumValue.
Return
this value if it's greater than or equal to the minimumValue or the minimumValue otherwise.
Since Kotlin
1.5
Samples
import samples.*
import java.time.DayOfWeek
import kotlin.test.assertFailsWith
fun main() {
//sampleStart
assertPrints(10u.coerceAtLeast(5u), "10")
assertPrints(10u.coerceAtLeast(20u), "20")
//sampleEnd
}