https://kotlinlang.org logo
#announcements
Title
# announcements
l

Luigi Scarminio

10/09/2019, 11:25 AM
I have this double number that I want to check if is between an interval. I was using "in", but now is marked as deprecated. I understand that there was a mixin creating some confusion. So what is the proper way to do this?
s

spand

10/09/2019, 11:51 AM
Works for me:
Copy code
fun main(args: Array<String>) {
    println(1.5 in (1.0..2.0))
}
s

Stephan Schroeder

10/09/2019, 12:27 PM
coerceIn
might be interesting to you as well. e.g.
Copy code
val d: Double = getSomeDouble().coerceIn(0.0, 10.0)
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.ranges/coerce-in.html
l

Luigi Scarminio

10/10/2019, 5:23 PM
Johannes Jensen, isn't it marked as deprecated?
s

spand

10/11/2019, 6:32 AM
Clicking on the
in
I get:
Copy code
@SinceKotlin("1.1")
public interface ClosedFloatingPointRange<T : Comparable<T>> : ClosedRange<T> {
    override fun contains(value: T): Boolean = lessThanOrEquals(start, value) && lessThanOrEquals(value, endInclusive)
    override fun isEmpty(): Boolean = !lessThanOrEquals(start, endInclusive)

    /**
     * Compares two values of range domain type and returns true if first is less than or equal to second.
     */
    fun lessThanOrEquals(a: T, b: T): Boolean
}
No deprecations as far as I can see
l

Luigi Scarminio

10/14/2019, 7:20 PM
Thanks!