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 exclusive range.
Convenience for make(start, end, true)
Parse from string format - inclusive is "start..end", or exclusive is "start..<end"
Convenience for make(start, end, false)
Constructor with start, end, and exclusive flag (all must be non-null)
If inclusive return "start..end", if exclusive return "start..<end"
Is the end index inclusive
Get the last value of the range
Create a new range by adding offset to this range's start and end values
Get the maximum value of the range
Return if this range contains no integer values
Return start index
Convert this range into a list of Ints
Call the specified function for each integer in the range
Convenience for Int.random(this)
Return if this range contains the specified integer
Get the minimum value of the range
Return true if same start, end, and exclusive
Is the end index exclusive
Return end index
Iterate every integer in the range until the function returns non-null
Create a new list which is the result of calling c for every integer in the range
Get the first value of the range
Return start ^ end
Bool contains(Int i)
Return if this range contains the specified integer.
Example:
(1..3).contains(2) => true (1..3).contains(4) => false
Void each(|Int| c)
Call the specified function for each integer in the range. Also see Int.times.
Example:
(1..3).each |i| { echo(i) } => 1, 2, 3
(1..<3).each |i| { echo(i) } => 1, 2
('a'..'z').each |Int i| { echo(i) } => 'a', 'b', ... 'z'
Obj? eachWhile(|Int->Obj?| c)
Iterate every integer in the range until the function returns non-null. If function returns non-null, then break the iteration and return the resulting object. Return null if the function returns null for every integer in the range.
Int end()
Return end index.
Example:
(1..3).end => 3
virtual Bool equals(Obj? obj)
Return true if same start, end, and exclusive.
Bool exclusive()
Is the end index exclusive.
Example:
(1..3).exclusive => false (1..<3).exclusive => true
Int? first()
Get the first value of the range. If range contains no values then return null. Equivalent to toList.first.
static new fromStr(Str s, Bool checked)
Parse from string format - inclusive is "start..end", or exclusive is "start..<end". If invalid format then throw ParseErr or return null based on checked flag.
virtual Int hash()
Return start ^ end.
Bool inclusive()
Is the end index inclusive.
Example:
(1..3).inclusive => true (1..<3).inclusive => false
Bool isEmpty()
Return if this range contains no integer values. Equivalent to toList.isEmpty.
Int? last()
Get the last value of the range. If range contains no values then return null. Equivalent to toList.last.
new make(Int start, Int end, Bool exclusive)
Constructor with start, end, and exclusive flag (all must be non-null).
new makeExclusive(Int start, Int end)
Convenience for make(start, end, true).
new makeInclusive(Int start, Int end)
Convenience for make(start, end, false).
Obj?[] map(|Int->Obj?| c)
Create a new list which is the result of calling c for every integer in the range. The new list is typed based on the return type of c.
Example:
(10..15).map |i->Str| { i.toHex } => Str[a, b, c, d, e, f]
Int? max()
Get the maximum value of the range. If range contains no values then return null. Equivalent to toList.max.
Int? min()
Get the minimum value of the range. If range contains no values then return null. Equivalent to toList.min.
Range offset(Int offset)
Create a new range by adding offset to this range's start and end values.
Example:
(3..5).offset(2) => 5..7 (3..<5).offset(-2) => 1..<3
Int random()
Convenience for Int.random(this). Also see Int.random, Float.random, List.random, and Random.
Int start()
Return start index.
Example:
(1..3).start => 1
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]
virtual Str toStr()
If inclusive return "start..end", if exclusive return "start..<end".