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
- containsSource
-
Return if this range contains the specified integer.
Example:
(1..3).contains(2) => true (1..3).contains(4) => false
- eachSource
-
Call the specified function for each integer in the range.
Example:
('a'..'z').each |Int i| { echo(i) }
- endSource
-
Int end()
Return end index.
Example:
(1..3).end => 3
- equalsSource
-
override Bool equals(Obj? obj)
Overrides sys::Obj.equals
Return true if same start, end, and exclusive.
- exclusiveSource
-
Bool exclusive()
Is the end index exclusive.
Example:
(1..3).exclusive => false (1..<3).exclusive => true
- hashSource
-
override Int hash()
Overrides sys::Obj.hash
Return start ^ end.
- inclusiveSource
-
Bool inclusive()
Is the end index inclusive.
Example:
(1..3).inclusive => true (1..<3).inclusive => false
- makeSource
-
new make(Int start, Int end, Bool exclusive)
Constructor with start, end, and exclusive flag (all must be non-null).
- makeExclusiveSource
-
new makeExclusive(Int start, Int end)
Convenience for make(start, end, true).
- makeInclusiveSource
-
new makeInclusive(Int start, Int end)
Convenience for make(start, end, false).
- randomSource
-
Int random()
Convenience for
Int.random(this)
. - startSource
-
Int start()
Return start index.
Example:
(1..3).start => 1
- toListSource
-
Int[] toList()
Convert this range into a list of Ints.
Example:
(2..4).toList => [2,3,4] (2..<4).toList => [2,3] (10..8).toList => [10,9,8]
- toStrSource
-
override Str toStr()
Overrides sys::Obj.toStr
If inclusive return "start..end", if exclusive return "start..<end".