type
Range
@Serializable { simple=true }
const class Range : Obj
Range represents a contiguous range of integers from start to end. Ranges may be represented as literals in Fantom source code as "start..end" for an inclusive end or "start..<end" for an exlusive range.
constructors
fromStr |
Parse from string format - inclusive is "start..end", or exclusive is "start..<end". |
---|---|
make |
Constructor with start, end, and exclusive flag (all must be non-null). |
makeExclusive |
Convenience for make(start, end, true). |
makeInclusive |
Convenience for make(start, end, false). |
methods
contains |
Return if this range contains the specified integer. |
---|---|
each |
Call the specified function for each integer in the range. |
eachWhile |
Iterate every integer in the range until the function returns non-null. |
end |
Return end index. |
equals |
Return true if same start, end, and exclusive. |
exclusive |
Is the end index exclusive. |
first |
Get the first value of the range. |
hash |
Return start ^ end. |
inclusive |
Is the end index inclusive. |
isEmpty |
Return if this range contains no integer values. |
last |
Get the last value of the range. |
map |
Create a new list which is the result of calling c for every integer in the range. |
max |
Get the maximum value of the range. |
min |
Get the minimum value of the range. |
offset |
Create a new range by adding offset to this range's start and end values. |
random |
Convenience for |
start |
Return start index. |
toList |
Convert this range into a list of Ints. |
toStr |
If inclusive return "start..end", if exclusive return "start..<end". |
Slot Details
contains
each
eachWhile
end
equals
exclusive
Bool exclusive()
Is the end index exclusive.
Example:
(1..3).exclusive => false (1..<3).exclusive => true
first
Int? first()
Get the first value of the range. If range contains no values then return null. Equivalent to toList.first
.
fromStr
hash
virtual override Int hash()
Return start ^ end.
inclusive
Bool inclusive()
Is the end index inclusive.
Example:
(1..3).inclusive => true (1..<3).inclusive => false
isEmpty
Bool isEmpty()
Return if this range contains no integer values. Equivalent to toList.isEmpty
.
last
Int? last()
Get the last value of the range. If range contains no values then return null. Equivalent to toList.last
.
make
makeExclusive
makeInclusive
map
max
Int? max()
Get the maximum value of the range. If range contains no values then return null. Equivalent to toList.max
.
min
Int? min()
Get the minimum value of the range. If range contains no values then return null. Equivalent to toList.min
.
offset
random
Int random()
Convenience for Int.random(this)
. Also see Int.random
, Float.random
, List.random
, and Random
.
start
toList
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]
toStr
virtual override Str toStr()
If inclusive return "start..end", if exclusive return "start..<end".