the sequence once looks shorter: ``` inline fun &l...
# random
k
the sequence once looks shorter:
Copy code
inline fun <T : Comparable<T>> ClosedRange<T>.toSequence(crossinline succ: T.() -> T): Sequence<T> {
    if (start > endInclusive) return emptySequence()
    return generateSequence(start) {
        val next = it.succ()
        if (next <= endInclusive) next else null
    }
}
or even shorter but with more indirection:
Copy code
fun <T : Comparable<T>> ClosedRange<T>.toSequence(succ: T.() -> T) = generateSequence(start, succ).takeWhile { it <= endInclusive }