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: 17

Methods

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

Example

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

Returns

Arr
[](s:Str, range:NumRange)
Get substring

Example

"abcd"[1..3]  # "bc"
[](arr:Arr, r:NumRange) Source: stdlib.ngs:3347
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]
[](s:Str, r:NumRange) Source: stdlib.ngs:4820
Get a substring. Indexes in s are specified by NumRange.

Parameters

sOriginal string
rNumRange with negatve .end

Returns

Str

Example

"(Look ma, no parens)"[1..-1]  # "Look ma, no parens"
[]=(arr:Arr, range:NumRange, replacement:Arr)
Set array elements at specified indexes.

Returns

replacement
[]=(s:Str, range:NumRange, replacement:Str)
Change substring

Returns

replacement

Example

s="abcd"; s[1..3]="X"; s  # "aXd"
each(r:NumRange, cb:Fun) Source: stdlib.ngs:2659
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:2715
Checks that x is in the range.

Example

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

Example

$(ok:0..10 ls no-such-file)
in(n:Int, r:NumRange) Source: stdlib.ngs:2670
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:1299
Undocumented
init(i:RangeIter, r:NumRange)
Initialize RangeIter. Will throw NotImplemented if r.start or r.step are not Int
Iter(r:NumRange)
Create Iter from NumRange
len(r:NumRange) Source: stdlib.ngs:2693
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:8343
Pick one random element from a range

Returns

Any