Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- infix fun ClosedRange<Float>.step(step: Float): Iterable<Float> {
- require(start.isFinite())
- require(endInclusive.isFinite())
- require(step > 0.0) { "Step must be positive, was: $step." }
- val sequence = generateSequence(start) { previous ->
- if (previous == Float.POSITIVE_INFINITY) return@generateSequence null
- val next = previous + step
- if (next > endInclusive) null else next
- }
- return sequence.asIterable()
- }
Add Comment
Please, Sign In to add comment