Guest User

Untitled

a guest
Jan 6th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. infix fun ClosedRange<Float>.step(step: Float): Iterable<Float> {
  2. require(start.isFinite())
  3. require(endInclusive.isFinite())
  4. require(step > 0.0) { "Step must be positive, was: $step." }
  5. val sequence = generateSequence(start) { previous ->
  6. if (previous == Float.POSITIVE_INFINITY) return@generateSequence null
  7. val next = previous + step
  8. if (next > endInclusive) null else next
  9. }
  10. return sequence.asIterable()
  11. }
Add Comment
Please, Sign In to add comment