NumRange type

Numerical range

Direct parent types

Range
A range
Direct subtypes: 2
Eachable1
Eachable which each() calls the callback with one argument
Direct subtypes: 18

Methods

=~(x:Any, nr:NumRange, _mc:MatchContext) Source: stdlib.ngs:2965
Checks whether x is in the range.

Example

1 =~ 0..5  # true
[](arr:Arr, range:NumRange)
Get array elements at specified indexes.

Parameters

rangeNumRange, exclusive end. Non-negative Int .start. Non-negative Int .end, or null .end for the end of the array

Returns

Arr

Example

[10,20,30,40][1..3]  # [20,30]
[10,20,30,40][1..null]  # [20,30,40]
[](s:Str, range:NumRange)
Get substring

Parameters

rangeNumRange, exclusive end. Non-negative Int .start. Non-negative Int .end, or null .end for the end of the string

Example

"abcd"[1..3]  # "bc"
"abcd"[1..null]  # "bcd"
[](arr:Arr, r:NumRange) Source: stdlib.ngs:3616
Get array elements at specified indexes. Indexes specified by NumRange.

Parameters

rNumRange with negative .end

Returns

Arr

Example

[10,20,30,40][1..-1]  # [20,30]
[](arr:Arr, r:NumRange) Source: stdlib.ngs:3629
Get array elements at specified indexes. Indexes specified by NumRange.

Parameters

rNumRange with negative .start

Returns

Arr

Example

[10,20,30,40][-2..null]  # [30,40]
[](s:Str, r:NumRange) Source: stdlib.ngs:5161
Get a substring. Indexes in s are specified by NumRange.

Parameters

sOriginal string
rNumRange with negative .end

Returns

Str

Example

"(Look ma, no parens)"[1..-1]  # "Look ma, no parens"
[](s:Str, r:NumRange) Source: stdlib.ngs:5172
Get a substring. Indexes in s are specified by NumRange.

Parameters

sOriginal string
rNumRange with negative .start

Returns

Str

Example

"abcd"[-2..null]  # "cd"
[]=(arr:Arr, range:NumRange, replacement:Arr)
Set array elements at specified indexes.

Parameters

rangeNumRange, exclusive end. Non-negative Int .start. Non-negative Int .end, or null .end for the end of the array

Returns

replacement

Example

a=[1,2,3,4]; a[1..3]=[9]; a  # [1,9,4]
a=[1,2,3,4]; a[1..null]=[9]; a  # [1,9]
[]=(s:Str, range:NumRange, replacement:Str)
Change substring

Parameters

rangeNumRange, exclusive end. Non-negative Int .start. Non-negative Int .end, or null .end for the end of the string

Returns

replacement

Example

s="abcd"; s[1..3]="X"; s  # "aXd"
s="abcd"; s[1..null]="XY"; s  # "aXY"
each(r:NumRange, cb:Fun) Source: stdlib.ngs:2920
Iterates over the elements of r, passing each in turn to cb.

Parameters

cbFunction to be called with values from r

Returns

r

Example

s=0
(1...10).each(F(i) { global s; s+=i })
echo(s)  # Outputs: 55
ensure(n:Int, r:NumRange) Source: stdlib.ngs:2977
Ensures that x is in the range.

Example

ensure(1, 3..10)    # 3
ensure(20, 3...10)  # 10
finished_ok(p:Process, field_name:Str, ok:NumRange)internal Source: stdlib.ngs:6886
Decide whether a process finished normally.

Example

$(ok:0..10 ls no-such-file)
in(n:Int, r:NumRange) Source: stdlib.ngs:2931
Check whether the number is in range 10 in 10..20 # true 1 in 10..20 # false
init(r:Repeat, pattern:Any, count:NumRange) Source: stdlib.ngs:1450
Undocumented
init(r:NumRange, start:Any, end:Any, include_start:Any=true, include_end:Any=false, step:Any=1) Source: stdlib.ngs:2899
NumRange constructor. Validates that start and end are Num or Null, step is Num.
init(i:RangeIter, r:NumRange) Source: autoload/globals/Iter.ngs:250
Initialize RangeIter. Will throw NotImplemented if r.start or r.step are not Int
Iter(r:NumRange) Source: autoload/globals/Iter.ngs:243
Create Iter from NumRange
len(r:NumRange) Source: stdlib.ngs:2954
Length of a NumRange. Only defined for Int start and end. Equals to how many times cb will be invoked in each(r, cb).
rand(r:NumRange) Source: stdlib.ngs:9089
Pick one random element from a range

Returns

Any