Hullaballoonatic
07/05/2020, 9:33 PMfun <C : Comparable<C>> C.coerceAtMost(maxValue: C) = if (this > maxValue) maxValue else this
fun <C : Comparable<C>> C.coerceAtLeast(minValue: C) = if (this < minValue) minValue else this
fun <C : Comparable<C>> C.coerceIn(minValue: C, maxValue: C) = coerceAtLeast(minValue).coerceAtMost(maxValue)
Also
fun <C : Comparable<C>> min(vararg elements: C): C
fun <C : Comparable<C>> max(vararg elements: C): C
I'm a bit surprised these methods aren't part of stdlib of any languages i know of. Is there a reason I haven't considered?MiSikora
07/06/2020, 11:22 AMHullaballoonatic
07/07/2020, 11:13 PM