G'day:
This is a bit of a nostalgia trip. But until those nostalgia trips that are all sepia-coloured and star Jimmy Stewart and harken back to better times: this should make us thankful we are where we are.
Last week I decided to clear out a few of the UDFs in the CFLib backlog. I wrote an article about one of the ones I processed in my last article - "
Feedback on UDF submitted to CFLib" - and I'm gonna continue on with the next one I looked at.
This one is a facsimile of
arrayMap()
: back porting the functionality of ColdFusion 11's new function to work on older versions of CF. As written, it would have only worked back as far as CF8, but it was a reasonable effort. On CFLib I don't give a toss about versions of CF prior to CF9 (and even then, only until December when it is end-of-lifed; after that I'll only be targeting a minimum of CF10), so the version I release is CF9 compatible. And is as follows:
array function arrayMap(required array array, required any f){
if (!isCustomFunction(f)){
throw(type="InvalidArgumentException", message="The 'f' argument must be a function");
}
var result = [];
var arrLen = arrayLen(array);
for (var i=1; i <= arrLen; i++){
arrayAppend(result, f(array[i], i, array));
}
return result;
}
(I'm actually glad I revisited this, as I spotted a bug with it when I did: I had some CF10-only code in it).
That works fine. It lacks the elegance of ColdFusion 11's implementation as it cannot use an inline function expression (which is kinda the whole "thing" about these iteration functions), but it does the mapping OK.
This got me thinking (and mildly investigating) how CFML has changed over the years, and what code one would need to write to effect this functionality using progressively older versions of CFML. To start with, let's look at the bleeding edge state of affairs (the bleeding edge in this context currently being Railo 4.2, not ColdFusion 11).