← index

NumberRangesealed

inherits Object · mixes in Iterate · defined at core/03-number_range.qn:13

A numeric interval from start toward end - end-EXCLUSIVE - iterating in steps of 1 (counting down when start > end).

Created with the .. operator on Integer or Double. Mixes in Iterate, so every collection combinator works on it; the match operator ~ (as used by Case when:do: arms) tests containment in the same end-exclusive interval.

(1..5).list    "* -> #(1 2 3 4)
(3..0).list    "* -> #(3 2 1)

Instance methods

each:

Call the block with each number from start toward end (end excluded), stepping by 1 in the range's direction.

var t = 0; (1..5).each:{ |i| t = t + i }; t    "* -> 10

core/03-number_range.qn:50

init:

Bind the bounds and choose the step: +1 upward, -1 when start > end. Ranges are normally created with start..end rather than new:.

core/03-number_range.qn:18

s

The readable form of the range.

(1..5).s    "* -> NumberRange(1..5)

core/03-number_range.qn:30

~:

Containment test for the match operator: true when n lies inside the end-exclusive interval (this is what a range condition in a Case when:do: arm checks).

(1..5) ~ 3    "* -> true
(1..5) ~ 5    "* -> false

core/03-number_range.qn:40