PredRange type
Direct parent types
- Range
A range Direct subtypes: 2
Methods
- [](arr:Arr, r:PredRange) Source: stdlib.ngs:3396
Extract array elements between the element that matches r.start and the element that matches r.end . Starting and ending elements are optionally included, depending on r.include_start and r.include_end . Example
%[a1 a2 b1 b2][/^a/../^b/] # ['a2'] %[a1 a2 b1 b2][/^a/.../^b/] # ['a1', 'a2', 'b1'] %[a1 a2 b1 b2][/^a/.../^x/] # IndexNotFound exception
- []=(arr:Arr, r:PredRange, replacement:Arr) Source: stdlib.ngs:3413
Replace array elements. Parameters
arr Array to operate on. r Range of elements to replace. replacement New elements. Example
a = %[a1 a2 b1 b2] a[/^a/.../^b/] = [7] # a == [7, 'b2'] MARKERS = '# generated - start'..'# generated - end' text[MARKERS] = newly_generated_content_lines
- indexes(arr:Arr, r:PredRange, dflt:Any=block) Source: stdlib.ngs:3364
Find the indexes of elements of the given PredRange. Throws IndexNotFound if there is no match between the elements of arr and r. Returns
NumRange with .include_start=true and .include_end=falseExample
%[a1 a2 b1 b2 c1].indexes(/^a/../^b/) # <NumRange 1..2 include_start=true include_end=false step=1> %[a1 a2 b1 b2 c1].indexes(/^a/.../^b/) # <NumRange 0..3 include_start=true include_end=false step=1>
- ~(arr:Arr, r:PredRange) Source: stdlib.ngs:3424
Check whether the array contains the given range. Finds first match. Returns
MatchResultExample
a = %[a1 a2 b1 b2] m = a ~ /^a/../^b/ # Exclusive range # m.matches == [['a2']] # m.before == ['a1'] # m.after == ['b1', 'b2']