Minor edits in in_list

This commit is contained in:
RonaldoCMP 2020-07-31 00:59:05 +01:00
parent 5c239187e9
commit 74cc246c75

View file

@ -108,14 +108,16 @@ function slice(list,start,end) =
// Arguments:
// val = The simple value to search for.
// 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:
// in_list("bar", ["foo", "bar", "baz"]); // Returns true.
// in_list("bee", ["foo", "bar", "baz"]); // Returns false.
// in_list("bar", [[2,"foo"], [4,"bar"], [3,"baz"]], idx=1); // Returns true.
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] )
s==[] || s[0]==[] ? false
s==[] || s==[[]] ? false
: is_undef(idx) ? val==list[s]
: val==list[s][idx];