const class sys::Range

sys::Obj
  sys::Range

@Serializable { simple=true }

Source

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.

contains

Bool contains(Int i)

Source

Return if this range contains the specified integer.

Example:

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

Void each(|Int| c)

Source

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'
eachWhile

Obj? eachWhile(|Int->Obj?| c)

Source

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.

end

Int end()

Source

Return end index.

Example:

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

virtual override Bool equals(Obj? obj)

Source

Return true if same start, end, and exclusive.

exclusive

Bool exclusive()

Source

Is the end index exclusive.

Example:

(1..3).exclusive   =>  false
(1..<3).exclusive  =>  true
first

Int? first()

Source

Get the first value of the range. If range contains no values then return null. Equivalent to toList.first.

fromStr

static new fromStr(Str s, Bool checked := true)

Source

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.

hash

virtual override Int hash()

Source

Return start ^ end.

inclusive

Bool inclusive()

Source

Is the end index inclusive.

Example:

(1..3).inclusive   =>  true
(1..<3).inclusive  =>  false
isEmpty

Bool isEmpty()

Source

Return if this range contains no integer values. Equivalent to toList.isEmpty.

last

Int? last()

Source

Get the last value of the range. If range contains no values then return null. Equivalent to toList.last.

make

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

Source

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

makeExclusive

new makeExclusive(Int start, Int end)

Source

Convenience for make(start, end, true).

makeInclusive

new makeInclusive(Int start, Int end)

Source

Convenience for make(start, end, false).

map

Obj?[] map(|Int->Obj?| c)

Source

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]
max

Int? max()

Source

Get the maximum value of the range. If range contains no values then return null. Equivalent to toList.max.

min

Int? min()

Source

Get the minimum value of the range. If range contains no values then return null. Equivalent to toList.min.

offset

Range offset(Int offset)

Source

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
random

Int random()

Source

Convenience for Int.random(this). Also see Int.random, Float.random, List.random, and Random.

start

Int start()

Source

Return start index.

Example:

(1..3).start  =>  1
toList

Int[] toList()

Source

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()

Source

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