All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scalax.range.RangeIterator.scala Maven / Gradle / Ivy

The newest version!
package scalax.range

import scalax.range.RangeBuilder._


class RangeIterator[T, S](
  from: Endpoint[T],
  to: Endpoint[T],
  step: S)(implicit ord: Ordering[T], stepper: Stepper[T, S]) extends Iterator[T] {
  import ord._
  import stepper._

  private var pointer: T = if (from.inclusive) from.point else from.point + step

  override def hasNext: Boolean =
    if (to.inclusive) pointer <= to.point else pointer < to.point

  override def next(): T = {
    if (!hasNext) throw new NoSuchElementException("next on empty iterator")

    val e = pointer
    pointer += step

    e
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy