関数型プログラミングでこれを実現したい場合は、Underscore.cfc ライブラリを使用できます(CF 10 以降または 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);
このソリューションはreduce()
、クエリの配列を構造体の単一の配列に結合するために利用します。に渡された無名関数は、 をreduce()
使用してクエリの配列内の各クエリを構造体の配列に変換し、その配列をtoArray()
構造体の残りの配列 (memo
値) と連結します。
クエリの配列が構造体の単一の配列に変換されると、それを を使用してクエリに戻すのは簡単なことですtoQuery()
(それが必要であると仮定します)。
注: Underscore ライブラリを作成しました