mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-04 03:09:45 +00:00
Minor edits in in_list
This commit is contained in:
parent
5c239187e9
commit
74cc246c75
1 changed files with 4 additions and 2 deletions
|
@ -108,14 +108,16 @@ function slice(list,start,end) =
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// val = The simple value to search for.
|
// val = The simple value to search for.
|
||||||
// list = The list to search.
|
// list = The list to search.
|
||||||
// idx = If given, searches the given subindexes for matches for `val`.
|
// idx = If given, searches the given subindex for matches for `val`.
|
||||||
// Example:
|
// Example:
|
||||||
// in_list("bar", ["foo", "bar", "baz"]); // Returns true.
|
// in_list("bar", ["foo", "bar", "baz"]); // Returns true.
|
||||||
// in_list("bee", ["foo", "bar", "baz"]); // Returns false.
|
// in_list("bee", ["foo", "bar", "baz"]); // Returns false.
|
||||||
// in_list("bar", [[2,"foo"], [4,"bar"], [3,"baz"]], idx=1); // Returns true.
|
// in_list("bar", [[2,"foo"], [4,"bar"], [3,"baz"]], idx=1); // Returns true.
|
||||||
function in_list(val,list,idx=undef) =
|
function in_list(val,list,idx=undef) =
|
||||||
|
assert( is_list(list) && (is_undef(idx) || is_finite(idx)),
|
||||||
|
"Invalid input." )
|
||||||
let( s = search([val], list, num_returns_per_match=1, index_col_num=idx)[0] )
|
let( s = search([val], list, num_returns_per_match=1, index_col_num=idx)[0] )
|
||||||
s==[] || s[0]==[] ? false
|
s==[] || s==[[]] ? false
|
||||||
: is_undef(idx) ? val==list[s]
|
: is_undef(idx) ? val==list[s]
|
||||||
: val==list[s][idx];
|
: val==list[s][idx];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue