The Range class represents a numeric sequence defined by its start, end, and step values. It supports iteration and operations for checking, reversing, and copying a range.

Range.start

attribute range

Signature

Range:start

Description

The attribute start allows to receive the start value of a Tea range.

Example

const r = 1..10..2
print(r.start)  // 1

Range.end

attribute range

Signature

Range:end

Description

The attribute end allows to receive the end value of a Tea range.

Example

const r = 1..10..2
print(r.end)  // 10

Range.step

attribute range

Signature

Range:step

Description

The attribute step allows to receive the step value of a Tea range.

Example

const r = 1..10..2
print(r.step)  // 2

Range.len

attribute range

Signature

Range:len

Description

The attribute len allows to receive the number of elements in a Tea range.

Example

const r = 1..10..2
print(r.len)  // 4.5

Range.new

method range

Signature

function Range:new(start, end, step=1)

Description

The new method creates a new Tea range.

Parameters

start
The starting value of the range.
end
The ending value of the range.
step
An optional number that specifies the increment between each value in the range. If step is not specified, the default value is 1.

Example

var r = 1..10
print(r.start)  // 1
print(r.end)    // 10
print(r.step)   // 1

Range.contains

method range

Signature

Check number presence

Description

The contains method checks whether the specified number is found within the original range.

Parameters

number
The number to search for within the original range.

Returns

The method returns true if the number is found within the original range, or false otherwise.

Example

var r = 1..10..2
var result = r.contains(3)
print(result)  // true

result = r.contains(4)
print(result)  // false

Range.reverse

method range

Signature

function Range:reverse()

Description

The reverse method reverses the original range in place.

Example

var r = 1..10..2
r.reverse()
print(r.start)  // 10
print(r.end)    // 1
print(r.step)   // -2

Range.copy

method range

Signature

function Range:copy()

Description

The copy method produces a new Tea range copy of the original range.

Example

var r = 1..10..2
var r2 = r.copy()
print(r2.start)  // 1
print(r2.end)    // 10
print(r2.step)   // 2

Range.iter

method range

Signature

function Range:iter()

Description

The iter method produces an iterator for the original range.