PredRange type

A range with start and end expressed as predicates.

Direct parent types

Range
A range
Direct subtypes: 2

Methods

[](arr:Arr, r:PredRange) Source: stdlib.ngs:2098
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:2115
Replace array elements.

Parameters

arrArray to operate on.
rRange of elements to replace.
replacementNew 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=[]) Source: stdlib.ngs:2067
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=false

Example

%[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:2126
Check whether the array contains the given range. Finds first match.

Returns

MatchResult

Example

a = %[a1 a2 b1 b2]
m = a ~ /^a/../^b/ # Exclusive range
# m.matches == [['a2']]
# m.before == ['a1']
# m.after == ['b1', 'b2']