chicple.blogg.se

Kotlin range inclusive
Kotlin range inclusive




kotlin range inclusive

It will be interesting to see if it will be marked as intended behaviour or not. Seems like there is already a bug filed for this.

kotlin range inclusive

If you use the rangeTo operator in this way, you’d be best sanity checking you aren’t passing it floats as an input value anywhere. This is a breaking change between Kotlin versions that could easily catch anyone out. If the float as an input is supported, then it should be honoured, and not silently cast to an integer. This would eliminate the chance for error. With 1.1.3, if it isn’t going to use a float, and instead silently cast to an integer, I feel like the API shouldn’t support the float as input in the first place. Oddly, it feels like the implementation of 1.0.7 is more intuitive, and simple.

it returns false if x < minValue or x > maxValue - i.e. kotlin range inclusive

While I’m assured that Kotlin does its best not to surprise you with silent casts like this, it does happen. ValueRange range .of (minValue, maxValue) range.isValidIntValue (x) it returns true if minValue < x < MaxValue - i.e. The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and stops before a specified number. Thanks to Pavlos Petros Tournaris for finding the commit in Kotlin source code where the change was made: Summary It also lets you set the Kotlin version that’ll be used to run the code. If you want to try this out for yourself, check out which is an online code playground where you write some Kotlin and get immediate output. This means that 10.5 becomes 10 and then is determined to be in the range. With 1.1.3, it silently casts the float to an integer first.






Kotlin range inclusive