Michael de Kaste
01/17/2023, 10:40 AMdate1..null // Range.BoundedLeft<LocalDateTime>
null..date2 // Range.BoundedRight<LocalDateTime>
date1..date2 // Range.Closed<LocalDateTime>
For this we made an operator fun on the rangeTo operator for comparable classes. This works fine for things like dates and custom classes. But if I want to use the rangeTo on an Int, there is no way for me to set the precedence of my own utility function over that of the construction of an IntRange, is this fixable? I know I can import my custom rangeTo
as somethingElse
, but I'd like to be able to do the following:
val range: Range.Closed = 1..3
ephemient
01/17/2023, 10:49 AMrangeTo
operator so that
x in y..z
for (x in y..z)
do not construct range instances but are instead compiled as simple range checks and loopsMichael de Kaste
01/17/2023, 10:58 AM1..null
works fineAdam S
01/17/2023, 11:08 AMfun main() {
val range: Range.Closed<Int> = (1..5).closed
}
val <T: Comparable<T>> ClosedRange<T>.closed
get() = Range.Closed(this)
Michael de Kaste
01/17/2023, 11:23 AMwhen(date){
in null..someRange -> "thing1"
in someRange..someOtherRange -> "thing2"
in someOtherRange..null -> "thing3"
}
ephemient
01/18/2023, 12:43 AMwhen {
date < someRange -> "thing1"
date <= someOtherRange -> "thing2"
else -> "thing3"
}