logo

const class

sys::Range

sys::Obj
  sys::Range

Range represents a contiguous range of integers from start to end. Ranges may be represented as literals in Fan source code as "start..end" for an inclusive end or "start...end" for an exlusive range.

Slots

contains

Bool contains(Int i)

Return if this range contains the specified integer.

Example:

(1..3).contains(2)  ->  true
(1..3).contains(4)  ->  false
each

Void each(|Int| c)

Call the specified function for each integer in the range.

Example:

('a'..'z').each |Int i| { echo(i) }
end

Int end()

Return end index.

Example:

(1..3).end -> 3
equals

override Bool equals(Obj obj)

Return true if same start, end, and exclusive.

exclusive

Bool exclusive()

Is the end index exclusive.

Example:

(1..3).exclusive -> false
(1...3).exclusive -> true
hash

override Int hash()

Return start ^ end.

inclusive

Bool inclusive()

Is the end index inclusive.

Example:

(1..3).inclusive -> true
(1...3).inclusive -> false
make

new make(Int start, Int end, Bool exclusive)

Constructor with start, end, and exclusive flag (all must be non-null).

makeExclusive

new makeExclusive(Int start, Int end)

Convenience for make(start, end, true).

makeInclusive

new makeInclusive(Int start, Int end)

Convenience for make(start, end, false).

start

Int start()

Return start index.

Example:

(1..3).start -> 1
toStr

override Str toStr()

If inclusive return "start..end", if exclusive return "start...end".