Title
h

hackerham

02/02/2017, 11:26 AM
float "for" cycle would be nice...
😱 1
m

miha-x64

02/02/2017, 11:46 AM
hackerham:
fun main(args: Array<String>) {
    for (i in 0f..5f) {
        println(i)
    }
    println((0f..0f).iterator().next()) // 0.0
    println((1f..0f).iterator().next()) // throws
}

operator fun ClosedRange<Float>.iterator(): Iterator<Float> =
        object : Iterator<Float> {
            val range = this@iterator
            var next: Float = range.start
            override fun hasNext(): Boolean =
                    next <= range.endInclusive
            override fun next(): Float {
                if (next > range.endInclusive) throw NoSuchElementException()
                return next++
            }
        }
h

hackerham

02/02/2017, 12:04 PM
thanks!