Return a negative integer, zero, or a positive integer if this object is less than, equal to, or greater than the specified object:
this < that => <0
this == that => 0
this > that => >0
This method may also be accessed via the <
<=
<=>
>=
and >
shortcut operators. If not overridden the default
implementation compares the toStr
representations. Also see docLang.
Examples:
3.compare(8) => -1
8.compare(3) => 1
8.compare(8) => 0
3 <=> 8 => -1 // shortcut for 3.compare(8)
Return if this range contains the specified integer.
Example:
(1..3).contains(2) => true
(1..3).contains(4) => false
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'
Return end index.
Example:
(1..3).end => 3
Is the end index exclusive.
Example:
(1..3).exclusive => false
(1..<3).exclusive => true
Get the first value of the range. If range contains no
values then return null. Equivalent to toList.first
.
Return start ^ end.
Is the end index inclusive.
Example:
(1..3).inclusive => true
(1..<3).inclusive => false
Return if this range contains no integer values. Equivalent
to toList.isEmpty
.
Get the last value of the range. If range contains no
values then return null. Equivalent to toList.last
.
Get the maximum value of the range. If range contains no
values then return null. Equivalent to toList.max
.
Get the minimum value of the range. If range contains no
values then return null. Equivalent to toList.min
.
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
Convenience for Int.random(this). Also see Int.random, Float.random, List.random, and util::Random.
Return start index.
Example:
(1..3).start => 1
Get an immutable representation of this instance or throw NotImmutableErr if this object cannot be represented as an immutable:
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]
If inclusive return "start..end", if exclusive return "start..<end".
Trap a dynamic call for handling. Dynamic calls are invoked with the -> shortcut operator:
a->x a.trap("x", null)
a->x() a.trap("x", null)
a->x = b a.trap("x", [b])
a->x(b) a.trap("x", [b])
a->x(b, c) a.trap("x", [b, c])
The default implementation provided by Obj attempts to use reflection. If name maps to a method, it is invoked with the specified arguments. If name maps to a field and args.size is zero, get the field. If name maps to a field and args.size is one, set the field and return args[0]. Otherwise throw UnknownSlotErr.
This method called whenever an it-block is applied to an
object. The default implementation calls the function with this
,
and then returns this
.
Static
echoWrite x.toStr
to standard output followed by newline. If x
is null then print "null". If no argument is provided then
print an empty line.
Optional
x: JsObjStatic
fromParse 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.
Optional
checked: booleanStatic
makeConstructor with start, end, and exclusive flag (all must be non-null).
Static
makeConvenience for make(start, end, true).
Static
makeConvenience for make(start, end, false).
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.