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:3683
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 . null r.start means from the first element, null r.end means to the last element, both inclusive regardless of .. or ... .

Example

%[a1 a2 b1 b2][/^a/../^b/]   # ['a2']
%[a1 a2 b1 b2][null../^b/]   # ['a1', 'a2']
%[a1 a2 b1 b2][/^b/..null]   # ['b2']
%[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:3700
Replace array elements.

Parameters

arrArray to operate on.
rRange of elements to replace. null r.start means from the first element, null r.end means to the last element, both inclusive regardless of .. or ... .
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=block) Source: stdlib.ngs:3641
Find the indexes of elements of the given PredRange. Throws IndexNotFound if there is no match between the elements of arr and r and dflt is not given.

Parameters

dfltDefault value. If dflt is a Fun, the result of dflt() is used instead.

Returns

NumRange with .include_start=true and .include_end=false, or Value(dflt)

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:3711
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']