coerceAtLeast

Common
JVM
JS
Native
1.0
fun <T : Comparable<T>> T.coerceAtLeast(minimumValue: T): T
(source)

Ensures that this value is not less than the specified minimumValue.

import java.time.DayOfWeek
import kotlin.test.assertFailsWith

fun main(args: Array<String>) {
//sampleStart
println(DayOfWeek.WEDNESDAY.coerceAtLeast(DayOfWeek.MONDAY)) // WEDNESDAY
println(DayOfWeek.WEDNESDAY.coerceAtLeast(DayOfWeek.FRIDAY)) // FRIDAY
//sampleEnd
}

Return this value if it's greater than or equal to the minimumValue or the minimumValue otherwise.

Common
JVM
JS
Native
1.0
fun Byte.coerceAtLeast(minimumValue: Byte): Byte
(source)
fun Short.coerceAtLeast(minimumValue: Short): Short
(source)
fun Int.coerceAtLeast(minimumValue: Int): Int
(source)
fun Long.coerceAtLeast(minimumValue: Long): Long
(source)
fun Float.coerceAtLeast(minimumValue: Float): Float
(source)
fun Double.coerceAtLeast(minimumValue: Double): Double
(source)

Ensures that this value is not less than the specified minimumValue.

import java.time.DayOfWeek
import kotlin.test.assertFailsWith

fun main(args: Array<String>) {
//sampleStart
println(10.coerceAtLeast(5)) // 10
println(10.coerceAtLeast(20)) // 20
//sampleEnd
}

Return this value if it's greater than or equal to the minimumValue or the minimumValue otherwise.

Common
JVM
JS
Native
1.5
fun UInt.coerceAtLeast(minimumValue: UInt): UInt
(source)
fun ULong.coerceAtLeast(minimumValue: ULong): ULong
(source)
fun UByte.coerceAtLeast(minimumValue: UByte): UByte
(source)
fun UShort.coerceAtLeast(minimumValue: UShort): UShort
(source)

Ensures that this value is not less than the specified minimumValue.

import java.time.DayOfWeek
import kotlin.test.assertFailsWith

fun main(args: Array<String>) {
//sampleStart
println(10u.coerceAtLeast(5u)) // 10
println(10u.coerceAtLeast(20u)) // 20
//sampleEnd
}

Return this value if it's greater than or equal to the minimumValue or the minimumValue otherwise.