Skip to content

Range[A: (Real[A] val & Number)]

[Source]

A bounded numeric sequence with a given step size. Two named constructors control whether the far bound is included:

  • Range.till — excludes the far bound
  • Range.through — includes the far bound

Direction is inferred: when from < to the range ascends, when from > to it descends. Step is always a positive magnitude.

A zero or negative step, or a non-finite float argument (NaN or infinity), produces an empty range.

// 0, 1, 2, 3, 4
for i in Range[USize].till(0, 5) do
  env.out.print(i.string())
end

// 5, 4, 3, 2, 1, 0
for i in Range[I32].through(5, 0) do
  env.out.print(i.string())
end

// with a step size
for i in Range[USize].till(0, 10, 2) do
  env.out.print(i.string())  // 0, 2, 4, 6, 8
end
class ref Range[A: (Real[A] val & Number)] is
  Iterator[A] ref

Implements


Constructors

through

[Source]

Inclusive of the far bound.

Range.through(0, 3) yields 0, 1, 2, 3. Range.through(3, 0) yields 3, 2, 1, 0. Range.through(5, 5) yields 5. Range.through(0, 9, 3) yields 0, 3, 6, 9. Range.through(0, 10, 3) yields 0, 3, 6, 9 — the step skips the far bound.

new ref through(
  from: A,
  to: A,
  step: A = 1)
: Range[A] ref^

Parameters

  • from: A
  • to: A
  • step: A = 1

Returns


till

[Source]

Exclusive of the far bound.

Range.till(0, 3) yields 0, 1, 2. Range.till(3, 0) yields 3, 2, 1. Range.till(5, 5) yields nothing.

new ref till(
  from: A,
  to: A,
  step: A = 1)
: Range[A] ref^

Parameters

  • from: A
  • to: A
  • step: A = 1

Returns


Public Functions

has_next

[Source]

True while there are values remaining in the sequence.

fun box has_next()
: Bool val

Returns


next

[Source]

Return the current value and advance. Errors when exhausted.

fun ref next()
: A ?

Returns

  • A ?

rewind

[Source]

Reset the iterator to its starting position.

fun ref rewind()
: None val

Returns