Basic Kotlin question here. If I wanted to move t...
# announcements
t
Basic Kotlin question here. If I wanted to move the decimalPrecision into the when (for example when(decimalPrecision)), is there a way I can still compare the value against <= 0 ?
🚫 1
you can overload method x.isNegative -> do shit
t
But it would allow me to do the isNegative as one of the conditions inside the when block?
I was trying to use a function there, but didnt' seem to work
For example
When I do this...
image.png
I can get by with that since the decimalPrecision allows comparison against each "constant"
But one of those branches can't be <= 0
I found this article
Guess it's not supported.
🙂
m
"OpenRanges" are not officially supported yet, however, you can write one yourself. you can then do:
Copy code
when(decimalPrecision){
    in <http://OpenRange.To|OpenRange.To>(0) -> "0%"
    null -> "0.00%"
    else -> ...
}
In our application, we use openranges for dates. We use codelists to indicate whether or not a code is active or not from a startDate until an endDate. However, sometimes, endDates are not filled in yet, indicating that the code will last forever.
I wish we could make constructors like this:
Copy code
..=0 "from -infinite until including 0"
...0 "from -infinite until excluding 0"
0=.. "from 0 including until infinity"
0... "from 0 excluding until infinity"
a man can dream