tracker issue : CF-3595198

select a category, or use search below
(searches all categories and all time range)
Title:

Please add more built-in closure functions: Array/Struct/List/QueryMap, Array/Struct/List/QueryReduce

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/

Reporter/Name(from Bugbase): Adam Tuttle / Adam Tuttle (Adam Tuttle)

Created: 07/15/2013

Components: Language

Versions: 10.0

Failure Type: Enhancement Request

Found In Build/Fixed In Build: Final / 286271

Priority/Frequency: Trivial / Unknown

Locale/System: English / Platforms All

Vote Count: 3

Arrays, Structures, Lists, and Queries all need map and reduce functions. Map should both update the complex data structure in-place AND return the updated data structure (to allow method nesting), and reduce functions should return the final simple data result of the reduction.

All of these functions should get multiple arguments:

updatedArray = arrayMap([1,2,3], function(elementValue, index, originalArray){ return elementValue * index; });

sumColB = queryReduce(foo, function(memo = 0, row, originalQuery){ return memo + row.B; });

IMPORTANT: the Memo argument should not be passed at all for the first iteration of a reduce function. If you pass an empty string or something of the wrong type then the specified default value will not be used and it will require additional param logic inside the closure, which would be bad. For all other iterations, memo should contain the value returned from the previous iteration.

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3595198

External Customer Info:
External Company:  
External Customer Name: Adam Tuttle
External Customer Email:

Attachments:

Comments:

Definitely +1. -- Adam
Vote by External U.
14960 | July 15, 2013 10:49:15 AM GMT
Map and reduce functions on queries would be a great addition to the CF toolset and allow us to write much cleaner, elegant code when it comes to doing in-memory/in-server calculations with query result sets!
Vote by External U.
14961 | July 15, 2013 12:53:55 PM GMT
Can we get some info on what's been implemented here? Cheers. -- Adam
Comment by External U.
14957 | September 20, 2013 03:48:28 AM GMT
Another common approach, beside not passing anything for the memo argument in the first iteration of the reduce, is to pass is initial value as a third argument to the reduce function: Sum = queryReduce(foo, function(){}, 0);
Comment by External U.
14958 | October 12, 2013 05:51:44 AM GMT
Please include map() and reduce() methods for query objects for language consistency! Yes, we know that the QoQ capability can typically accomplish the same thing but being able to keep the same paradigm across different data types leads to cleaner code.
Vote by External U.
14962 | October 28, 2013 06:35:45 AM GMT
test cases checked in.
Comment by Suchika S.
14959 | December 05, 2013 12:58:00 AM GMT