![]() |
omdl
v1.0
OpenSCAD Mechanical Design Library
|
Operations for iterable data types. More...
Collaboration diagram for Iterable Operations:Files | |
| file | iterable_operate.scad |
| Iterable data type operations. | |
Functions and/or Modules | |
| function | defined_e_or (v, i, d) |
| Returns an element from an iterable if it exists, or a default value if not. More... | |
| function | defined_eon_or (v, i, d) |
| Returns the list element or scalar numeric value if defined, otherwise returns the default value. More... | |
| function | defined_eonb_or (v, i, d) |
| Returns the list element or scalar numeric or boolean value if defined, otherwise returns the default value. More... | |
| function | defined_fle_or (v, i, d) |
| Return the first defined specified element in a list of lists, otherwise returns the given default value. More... | |
| function | defined_ei_or (v, i, d, n) |
| Returns an element from an iterable if it exists and is a iterable, otherwise returns a default value. More... | |
| function | find_all (mv, v) |
| Find all occurrences of a match value in an iterable value. More... | |
| function | find (mv, v, c=1, i, i1=0, i2) |
| Find the occurrences of a match value in an iterable value. More... | |
| function | count (mv, v, s=true, i) |
| Count all occurrences of a match value in an iterable value. More... | |
| function | exists (mv, v, s=true, i) |
| Check for the existence of a match value in an iterable value. More... | |
| function | exists_e (i, v) |
| Test if an element exists at a specified index of an iterable value. More... | |
| function | first (v) |
| Return the first element of an iterable value. More... | |
| function | second (v) |
| Return the second element of an iterable value. More... | |
| function | third (v) |
| Return the third element of an iterable value. More... | |
| function | last (v) |
| Return the last element of an iterable value. More... | |
| function | middle (v) |
| Return the middle element of an iterable value. More... | |
| function | first2 (v) |
| Return a list containing the first two elements of an iterable value. More... | |
| function | first3 (v) |
| Return a list containing the first three elements of an iterable value. More... | |
| function | last2 (v) |
| Return a list containing the last two elements of an iterable value. More... | |
| function | last3 (v) |
| Return a list containing the last three elements of an iterable value. More... | |
| function | firstn (v, n=1) |
Return a list containing the first n elements of an iterable value. More... | |
| function | lastn (v, n=1) |
Return a list containing the last n elements of an iterable value. More... | |
| function | headn (v, n=1) |
Return a list containing all but the last n elements of an iterable value. More... | |
| function | tailn (v, n=1) |
Return a list containing all but the first n elements of an iterable value. More... | |
| function | reverse (v) |
| Reverse the elements of an iterable value. More... | |
| function | shift_cd (v, n=0, r=true, d=false) |
| Circularly shift the elements of an iterable, with an optional element drop. More... | |
| function | shift_ci (v, n=0, r=true, i) |
| Shift-in a value to the elements of a given iterable value. More... | |
| function | select_r (v, i) |
| Select a range of elements from an iterable value. More... | |
| function | sequence_ns (v, n=1, s=1, w=false) |
| Return a list of all n-element sequential-subsets of an iterable value. More... | |
| function | combine_ns (v, n) |
| Return all n-sized set combinations of iterable value. More... | |
| function | permute_ns (v, n) |
| Return all ordered n-sized set permutations of iterable value. More... | |
| function | permute_ns_r (v, n) |
| Return all ordered n-size set permutations of iterable value with repetition allowed. More... | |
| function | append_e (nv, v, r=true, j=true, l=true) |
| Append a value to each element of an iterable value. More... | |
| function | append_v (nv, v, n=0, r=false) |
| Append a value to the end or beginning of an iterable value. More... | |
| function | insert (nv, v, i=0, mv, mi=0, s=true, si) |
| Insert a new value into an iterable value. More... | |
| function | delete_first (v, mv, mc=1) |
| Delete the first occurrence(s) of a matched value from an iterable value. More... | |
| function | delete_each (v, mv) |
| Delete each match value from an iterable value. More... | |
| function | delete (v, i, mv, mc=1, s=true, si) |
| Delete elements from an iterable value. More... | |
| function | replace_first (v, mv, nv, mc=1) |
| Replace the first occurrence(s) of a matched value in iterable value. More... | |
| function | strip (v, mv=empty_lst) |
| Strip all matching values from an iterable value. More... | |
| function | mask (v, m, r=false, o=0, u=undef, z=0) |
| Apply a binary mask to an interable value. More... | |
| function | unique (v) |
| Return a list of the unique elements of an iterable value. More... | |
| function | common (v1, v2, e=empty_lst) |
| Return a list of the common elements of two iterable values. More... | |
| function | not_common (v1, v2) |
| Return a list of the elements not present in both iterable values. More... | |
Operations for iterable data types.
| file | group | script | results | no test | skipped | passed | failed | warning |
|---|---|---|---|---|---|---|---|---|
| datatypes/iterable_operate.scad | Iterable Operations | Script | Results | 0 | 0 | 330 | 0 | 0 |
See complete validation results.
| Requires: |
|---|
| include <omdl-base.scad>; |
mv.mc. A value of 0 (or any value <= 0) means 'match all occurrences'. A positive value mc means 'match at most mc occurrences'.iv, not i. The parameter i is reserved for index positions throughout the group.mv takes precedence over i in functions that accept both: when mv is defined, the match is by value; i provides an optional secondary element index for structured-element matching.v never modify v in place.v is not iterable, most functions return v unchanged. Exceptions are documented individually. | function defined_e_or | ( | v | , |
| i | , | ||
| d | |||
| ) |
Returns an element from an iterable if it exists, or a default value if not.
| v | <iterable> An iterable value. |
| i | <integer> An element index. |
| d | <value> A default value. |
v[i] if it is defined, or d otherwise.
| function defined_eon_or | ( | v | , |
| i | , | ||
| d | |||
| ) |
Returns the list element or scalar numeric value if defined, otherwise returns the default value.
| v | <value> A value. |
| i | <integer> An element index. |
| d | <value> A default value. |
v if it is a scalar numeric value; (2) v[i] if it is defined, otherwise the default value d.
Here is the caller graph for this function:| function defined_eonb_or | ( | v | , |
| i | , | ||
| d | |||
| ) |
Returns the list element or scalar numeric or boolean value if defined, otherwise returns the default value.
| v | <value> A value. |
| i | <integer> An element index. |
| d | <value> A default value. |
v if it is a scalar numeric or boolean value; (2)
v[i] if it is defined, otherwise the default value d.
| function defined_fle_or | ( | v | , |
| i | , | ||
| d | |||
| ) |
Return the first defined specified element in a list of lists, otherwise returns the given default value.
| v | <value> A list of n elements lists. |
| i | <integer> The specified element index. |
| d | <value> A default value. |
v, a list of n lists, return the first element v[j][i] that is defined where j = [0 : n], otherwise the default value d.
Here is the caller graph for this function:| function defined_ei_or | ( | v | , |
| i | , | ||
| d | , | ||
| n | |||
| ) |
Returns an element from an iterable if it exists and is a iterable, otherwise returns a default value.
| v | <value> A value. |
| i | <integer> An element index. |
| d | <value> A default value. |
| n | <integer> The optional expected element length. |
v[i], a <list-n> if the element is iterable of length n (or <list> if n is unspecified), (2) or the default value d if the element is not defined.
Here is the caller graph for this function:| function find_all | ( | mv | , |
| v | |||
| ) |
Find all occurrences of a match value in an iterable value.
| mv | <value> A match value. |
| v | <iterable> An iterable value. |
mv. (2) Returns empty_lst when no element of v matches mv or when v is not iterable. | function find | ( | mv | , |
| v | , | ||
| c | = 1, |
||
| i | , | ||
| i1 | = 0, |
||
| i2 | |||
| ) |
Find the occurrences of a match value in an iterable value.
| mv | <value> A match value. |
| v | <iterable> An iterable value. |
| c | <integer> A match count. For (c >= 1), return the first c matches. For (c <= 0), return all matches. |
| i | <integer> The secondary element index to match for when the elements of v are themselves iterable elements. |
| i1 | <integer> The element index of v where the search begins. |
| i2 | <integer> The element index of v where the search ends. |
mv. (2) Returns empty_lst when no element of v matches mv or when v is not iterable.The use-cases for find() and search() are summarized in the following tables.
Find:
| mv / v | string | list of scalars | list of iterables |
|---|---|---|---|
| scalar | (a) | (b) see note 1 | |
| string | (c) | (b) see note 1 | |
| list of scalars | (b) see note 1 | ||
| list of iterables | (b) see note 1 |
Search:
| mv / v | string | list of scalars | list of iterables |
|---|---|---|---|
| scalar | (a) | (b) | |
| string | (d) | invalid | (e) see note 2 |
| list of scalars | (f) | (g) | |
| list of iterables | (g) |
Key:
v that equals mv. v where mv equals the element at the specified column index, i, of each iterable value in v. mv is a single character, identify each character in v that equals mv. mv, identify where it exists in v. empty_lst is returned for each character of mv absent from v. mv, identify where it exists in v either as a numeric value or as a character at the specified column index, i. empty_lst is returned for each character of mv absent from v. mv, identify where it exists in v. empty_lst is returned for each scalar of mv absent from v. mv, identify where it equals the element at the specified column index, i, of each iterable value in v. empty_lst is returned for each element of mv absent from v in the specified column index.i is specified, that element column is compared. Otherwise, the entire element is compared. Functions find() and search() behave differently in this regard. v is a string. However, an element that is a list of one or more strings is valid. In which case, only the first character of each string element is considered. | function count | ( | mv | , |
| v | , | ||
| s | = true, |
||
| i | |||
| ) |
Count all occurrences of a match value in an iterable value.
| mv | <value> A match value. |
| v | <iterable> An iterable value. |
| s | <boolean> Element matching search method. |
| i | <integer> The secondary element index to match for when the elements of v are themselves iterable elements. |
mv occurs in the list.When s == true, search() is used to match elements. When s == false, find() is used.
Here is the caller graph for this function:| function exists | ( | mv | , |
| v | , | ||
| s | = true, |
||
| i | |||
| ) |
Check for the existence of a match value in an iterable value.
| mv | <value> A match value. |
| v | <iterable> An iterable value. |
| s | <boolean> Element matching search method. |
| i | <integer> The secondary element index to match for when the elements of v are themselves iterable elements. |
mv exists in the list and false otherwise.When s == true, search() is used to match elements. When s == false, find() is used.
| function exists_e | ( | i | , |
| v | |||
| ) |
Test if an element exists at a specified index of an iterable value.
| i | <integer> An element index. |
| v | <iterable> An iterable value. |
v[i], exists and false otherwise. (2) Returns undef when i is not an number.i. | function first | ( | v | ) |
Return the first element of an iterable value.
| v | <iterable> An iterable value. |
v. (2) Returns undef when v is not defined, is not iterable, or is empty.
Here is the caller graph for this function:| function second | ( | v | ) |
Return the second element of an iterable value.
| v | <iterable> An iterable value. |
v. (2) Returns undef when v is not defined, is not iterable, or is empty.
Here is the caller graph for this function:| function third | ( | v | ) |
Return the third element of an iterable value.
| v | <iterable> An iterable value. |
v. (2) Returns undef when v is not defined, is not iterable, or is empty.
Here is the caller graph for this function:| function last | ( | v | ) |
Return the last element of an iterable value.
| v | <iterable> An iterable value. |
v. (2) Returns undef when v is not defined, is not iterable, or is empty.
Here is the caller graph for this function:| function middle | ( | v | ) |
Return the middle element of an iterable value.
| v | <iterable> An iterable value. |
v. (2) Returns undef when v is not defined, is not iterable, or is empty. | function first2 | ( | v | ) |
Return a list containing the first two elements of an iterable value.
| v | <iterable> An iterable value. |
v. (2) Returns undef when v is not defined, is not iterable, is empty or has less than two elements| function first3 | ( | v | ) |
Return a list containing the first three elements of an iterable value.
| v | <iterable> An iterable value. |
v. (2) Returns undef when v is not defined, is not iterable, is empty, or has less than three elements.| function last2 | ( | v | ) |
Return a list containing the last two elements of an iterable value.
| v | <iterable> An iterable value. |
v. (2) Returns undef when v is not defined, is not iterable, is empty, or has less than two elements. | function last3 | ( | v | ) |
Return a list containing the last three elements of an iterable value.
| v | <iterable> An iterable value. |
v. (2) Returns undef when v is not defined, is not iterable, is empty, or has less than three elements. | function firstn | ( | v | , |
| n | = 1 |
||
| ) |
Return a list containing the first n elements of an iterable value.
| v | <iterable> An iterable value. |
| n | <integer> The element count. |
n elements of v. (2) Returns undef when v is not defined, is not iterable, or is empty.When n is greater than the length of the iterable v, the list will stop at the last element of v.
Here is the caller graph for this function:| function lastn | ( | v | , |
| n | = 1 |
||
| ) |
Return a list containing the last n elements of an iterable value.
| v | <iterable> An iterable value. |
| n | <integer> The element count. |
n elements of v. (2) Returns undef when v is not defined, is not iterable, or is empty.When n is greater than the length of the iterable v, the list will start at the first element of v.
Here is the caller graph for this function:| function headn | ( | v | , |
| n | = 1 |
||
| ) |
Return a list containing all but the last n elements of an iterable value.
| v | <iterable> An iterable value. |
| n | <integer> The element count. |
n elements of v. (2) Returns empty_lst when v contains fewer than n elements. (3) Returns undef when v is not defined, is not iterable, or is empty.
Here is the caller graph for this function:| function tailn | ( | v | , |
| n | = 1 |
||
| ) |
Return a list containing all but the first n elements of an iterable value.
| v | <iterable> An iterable value. |
| n | <integer> The element count. |
n elements of v. (2) Returns empty_lst when v contains fewer than n elements. (3) Returns undef when v is not defined, is not iterable, or is empty.
Here is the caller graph for this function:| function reverse | ( | v | ) |
Reverse the elements of an iterable value.
| v | <iterable> An iterable value. |
v in reversed order. (2) Returns empty_lst when v is empty. (3) Returns undef when v is not defined or is not iterable.
Here is the caller graph for this function:| function shift_cd | ( | v | , |
| n | = 0, |
||
| r | = true, |
||
| d | = false |
||
| ) |
Circularly shift the elements of an iterable, with an optional element drop.
| v | <iterable> An iterable value. |
| n | <integer> The element shift count. |
| r | <boolean> Shift the elements to the right (or left). |
| d | <boolean> Drop elements outside of iterable value shift window. |
v shifted by n elements. (2) Returns undef when v is not defined or is not iterable.The shift count n may be positive or negative.
Here is the caller graph for this function:| function shift_ci | ( | v | , |
| n | = 0, |
||
| r | = true, |
||
| i | |||
| ) |
Shift-in a value to the elements of a given iterable value.
| v | <iterable> The iterable value. |
| n | <integer> The element shift count. |
| r | <boolean> Shift the elements to the right (or left). |
| i | <value> The value to shit-in on the left or right. |
v shifted by n elements with the value i inserted on the left or right side of the given iterable value. (2) Returns undef when v is not defined or is not iterable.The shift count n may be positive or negative.
| function select_r | ( | v | , |
| i | |||
| ) |
Select a range of elements from an iterable value.
| v | <iterable> An iterable value. |
| i | <range | list | integer> The index selection. |
v is not defined, is not iterable, or when i does not map to an element of v. (3) Returns empty_lst when v is empty. | function sequence_ns | ( | v | , |
| n | = 1, |
||
| s | = 1, |
||
| w | = false |
||
| ) |
Return a list of all n-element sequential-subsets of an iterable value.
| v | <iterable> An iterable value. |
| n | <integer> The number of elements for each subset. |
| s | <integer> The iteration step size. |
| w | <boolean> Use wrap-at-end circular subset selection. |
v skipping s elements of v between each subset selection. (2) Returns empty_lst when v is empty, is not defined or is not iterable.Example
Here is the caller graph for this function:| function combine_ns | ( | v | , |
| n | |||
| ) |
Return all n-sized set combinations of iterable value.
| v | <iterable> An iterable value. |
| n | <integer> The set size size. |
v. (2) Returns empty_lst when v is not iterable. | function permute_ns | ( | v | , |
| n | |||
| ) |
Return all ordered n-sized set permutations of iterable value.
| v | <iterable> An iterable value. |
| n | <integer> The set size size. |
v without repetition of elements. (2) Returns empty_lst when v is not iterable. | function permute_ns_r | ( | v | , |
| n | |||
| ) |
Return all ordered n-size set permutations of iterable value with repetition allowed.
| v | <iterable> An iterable value. |
| n | <integer> The set size size. |
v with element repetition allowed. (2) Returns empty_lst when v is not iterable. | function append_e | ( | nv | , |
| v | , | ||
| r | = true, |
||
| j | = true, |
||
| l | = true |
||
| ) |
Append a value to each element of an iterable value.
| nv | <value> A new value to append. |
| v | <iterable> An iterable value. |
| r | <boolean> Reduce list element before appending. |
| j | <boolean> Join each appendage as a separate list. |
| l | <boolean> Append new value to last element. |
nv appended to each element of v. (2) Returns undef when v is not defined or is not iterable.Appending with r == true causes each element of nv to be appended to the elements of each iterable value. When r == false, each element of nv is appended to the iterable value itself. To append a list of elements together as a list to v, enclose the elements of nv with a second set of brackets.
Example
Result
| function append_v | ( | nv | , |
| v | , | ||
| n | = 0, |
||
| r | = false |
||
| ) |
Append a value to the end or beginning of an iterable value.
| nv | <value> The value to append. |
| v | <iterable> An iterable value. |
| n | <integer> The element shift count. |
| r | <boolean> Shift the elements to the right (or left). |
v shifted by n elements with the value a appended the given iterable value as specified. (2) Returns undef when v is not defined or is not iterable.The shift count n may be positive or negative.
| function insert | ( | nv | , |
| v | , | ||
| i | = 0, |
||
| mv | , | ||
| mi | = 0, |
||
| s | = true, |
||
| si | |||
| ) |
Insert a new value into an iterable value.
| nv | <value> A new value to insert. |
| v | <iterable> An iterable value. |
| i | <integer> The index insert position. |
| mv | <list | string | value> Match value candidates. |
| mi | <integer> The matched selection index. |
| s | <boolean> Element matching search method. |
| si | <integer> The search element index when matching. |
nv inserted into v at the specified position. (2) Returns undef when no value of mv exists in v, when (mi + 1) exceeds the matched element count, when i does not map to an element of v, or when v is not defined or is not iterable.When s == true, search() is used to match elements. When s == false, find() is used.
The insert position can be specified by an index, an element match value, or list of potential match values. When multiple matches exists, mi indicates the insert position. When more than one insert position criteria is specified, the order of precedence is: (1) mv then (2) i. To insert a list of elements together as a list to v, enclose the elements of nv with a second set of brackets.
| function delete_first | ( | v | , |
| mv | , | ||
| mc | = 1 |
||
| ) |
Delete the first occurrence(s) of a matched value from an iterable value.
| v | <iterable> The iterable value. |
| mv | <value> The match value. |
| mc | <integer> A match count. For (mc >= 1), remove the first mc matches. For (mc = 0), remove all matches. |
mc occurrences of the match value removed. (2) Returns undef when v is not defined, or is not iterable. | function delete_each | ( | v | , |
| mv | |||
| ) |
Delete each match value from an iterable value.
| v | <iterable> An iterable value. |
| mv | <iterable> The list of match values. |
| function delete | ( | v | , |
| i | , | ||
| mv | , | ||
| mc | = 1, |
||
| s | = true, |
||
| si | |||
| ) |
Delete elements from an iterable value.
| v | <iterable> An iterable value. |
| i | <range | list | integer> Deletion Indexes. |
| mv | <list | string | value> Match value candidates. |
| mc | <integer> A match count. For (mc >= 1), remove the first mc matches. For (mc <= 0), remove all matches. |
| s | <boolean> Element matching search method. |
| si | <integer> The element column index when matching. |
i does not map to an element of v, when v is not defined, or is not iterable.When s == true, search() is used to match elements. When s == false, find() is used.
The elements to delete can be specified by an index position, a list of index positions, an index range, an element match value, or a list of element match values (when using search()). When mv is a list of match values, all values of mv that exists in v are candidates for deletion. For each matching candidate, mc indicates the quantity to remove. When more than one deletion criteria is specified, the order of precedence is: (1) mv then (2) i.
| function replace_first | ( | v | , |
| mv | , | ||
| nv | , | ||
| mc | = 1 |
||
| ) |
Replace the first occurrence(s) of a matched value in iterable value.
| v | <iterable> The iterable value. |
| mv | <value> The match value. |
| nv | <value> The new value. |
| mc | <integer> A match count. For (mc >= 1), replaces the first mc matches. For (mc = 0), replaces all matches. |
nv. (2) Returns undef when v is not defined, or is not iterable. | function strip | ( | v | , |
| mv | = empty_lst |
||
| ) |
Strip all matching values from an iterable value.
| v | <iterable> An iterable value. |
| mv | <value> A match value. |
mv removed. (2) Returns undef when v is not defined or is not iterable. | function mask | ( | v | , |
| m | , | ||
| r | = false, |
||
| o | = 0, |
||
| u | = undef, |
||
| z | = 0 |
||
| ) |
Apply a binary mask to an interable value.
| v | <iterable> An iterable value. |
| m | <iterable> A binary mask list (or string) of 0 or 1. |
| r | <boolean> Right align the mask to v value. |
| o | <integer> A positive or negative mask offset. |
| u | <value> The value assigned to elements of the mask that does not exists or are undefined in v. |
| z | <value> The value assigned to masked elements. |
v. (2) Returns v as a list when m is not defined. (3) Returns undef when m is not iterable or contains values other than zero or one.This mask may be specified as a list or string and is composed of ones and zeros. One indicates that an element value of v is passed and a zero indicates that a value of v is to be replaced with z.
| function unique | ( | v | ) |
Return a list of the unique elements of an iterable value.
| v | <iterable> An iterable value. |
v is not defined or is not iterable.v that have the value of undef are ignored and is not considered to be a unique. | function common | ( | v1 | , |
| v2 | , | ||
| e | = empty_lst |
||
| ) |
Return a list of the common elements of two iterable values.
| v1 | <iterable> The first iterable value. |
| v2 | <iterable> The second iterable value. |
| e | <iterable> The common elements list (used for recursion value tracking or may be initialed by user). |
v1 or v2 is empty. | function not_common | ( | v1 | , |
| v2 | |||
| ) |
Return a list of the elements not present in both iterable values.
| v1 | <iterable> The first iterable value. |
| v2 | <iterable> The second iterable value. |
v1 and v2 are identical, or when both are empty.