From 58857b439a210418eb098357da71c38bf2339f7f Mon Sep 17 00:00:00 2001 From: Revar Desmera Date: Wed, 10 Jul 2019 21:52:47 -0700 Subject: [PATCH] Added recursive= options to first_defined(), any_defined() and all_defined() --- common.scad | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/common.scad b/common.scad index 7c5fa0c..279eeee 100644 --- a/common.scad +++ b/common.scad @@ -33,7 +33,17 @@ function default(v,dflt=undef) = is_undef(v)? dflt : v; // Description: // Returns the first item in the list that is not `undef`. // If all items are `undef`, or list is empty, returns `undef`. -function first_defined(v,_i=0) = _i=len(v)? _cnt : num_defined(v,_i+1,_cnt // Function: any_defined() // Description: // Returns true if any item in the given array is not `undef`. -function any_defined(v) = first_defined(v) != undef; +// Arguments: +// v = The list whose items are being checked. +// recursive = If true, any sublists are evaluated recursively. +function any_defined(v,recursive=false) = first_defined(v,recursive=recursive) != undef; // Function: all_defined() // Description: // Returns true if all items in the given array are not `undef`. -function all_defined(v,_i=0) = _i= len(v)); +// Arguments: +// v = The list whose items are being checked. +// recursive = If true, any sublists are evaluated recursively. +function all_defined(v,recursive=false) = max([for (x=v) is_undef(x)||(recursive&&is_list(x)&&!all_defined(x))? 1 : 0])==0; // Section: Argument Helpers