If you'd like to accomplish this with functional programming, you could use the Underscore.cfc library (requires CF 10+ or Railo 4+):
// instantiate Underscore library
_ = new Underscore();
// convert the array of queries to a single array of structs
mergedArray = _.reduce(arrayOfQueries, function (memo, query) {
// convert current query to an array of structs
// and concatenate it to the rest of the result
return _.concat(memo, _.toArray(query));
}, []);
// convert the array of structs back to a query
mergedQuery = _.toQuery(mergedArray);
This solution utilizes reduce()
to combine the array of queries into a single array of structs. The anonymous function passed to reduce()
converts each query in the array of queries to an array of structs using toArray()
, then concatenates that array with the rest of the array of structs (the memo
value).
Once the array of queries has been converted to a single array of structs, it is a simple matter to convert it back to a query using toQuery()
(assuming that is necessary).
Note: I wrote the Underscore library