Hello,
What do you think is it worth adding the following extension to the Kotlin Library?
fun <T> ClosedRange<T>.toSequence(nextItem: (T) -> (T)) : Sequence<T> {
generateSequence(nextItem.start) { prev ->
val next = nextItem(prev)
when {
next <= endInclusive -> next
else -> null
}
}
}
Usage:
fun ClosedRange<LocalDate>.getDays(): Sequence<LocalDate> {
return toSequence {
plusDays(1)
}
}