array overlay
This commit is contained in:
parent
4ab8d82727
commit
1f2331c00a
2 changed files with 24 additions and 4 deletions
|
|
@ -50,19 +50,20 @@ CUSTOM_FUNCTION_SCRIPTS: Dict[str, str] = {
|
||||||
%regex_capture_groups
|
%regex_capture_groups
|
||||||
),
|
),
|
||||||
%array_size($2),
|
%array_size($2),
|
||||||
%eq
|
%lte
|
||||||
),
|
),
|
||||||
%and
|
%and
|
||||||
),
|
),
|
||||||
%array_first(
|
%array_overlay(
|
||||||
%array_apply_fixed(
|
%array_apply_fixed(
|
||||||
%array($1),
|
%array($1),
|
||||||
%string($0),
|
%string($0),
|
||||||
%regex_search
|
%regex_search
|
||||||
),
|
),
|
||||||
%array_extend( ['dummy'], $2 )
|
%array_extend( ['using all defaults'], $2 ),
|
||||||
|
True
|
||||||
),
|
),
|
||||||
'Number of regex capture groups must be the same for every input regex'
|
'Number of regex capture groups must be less than or equal to the number of defaults'
|
||||||
)
|
)
|
||||||
}""",
|
}""",
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,25 @@ class ArrayFunctions:
|
||||||
|
|
||||||
return Array(output)
|
return Array(output)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def array_overlay(
|
||||||
|
array: Array, overlap: Array, only_missing: Optional[Boolean] = None
|
||||||
|
) -> Array:
|
||||||
|
"""
|
||||||
|
Overlaps ``overlap`` onto ``array``. Can optionally only overlay missing indices.
|
||||||
|
"""
|
||||||
|
output: List[Resolvable] = []
|
||||||
|
output.extend(array.value)
|
||||||
|
|
||||||
|
overlap_only_missing = only_missing and only_missing.value
|
||||||
|
|
||||||
|
for idx, overlap_value in enumerate(overlap.value):
|
||||||
|
if overlap_only_missing and idx < len(array.value):
|
||||||
|
continue
|
||||||
|
output.insert(idx, overlap_value)
|
||||||
|
|
||||||
|
return Array(output)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def array_at(array: Array, idx: Integer) -> AnyArgument:
|
def array_at(array: Array, idx: Integer) -> AnyArgument:
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue