tracker issue : CF-4198483

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

Add higher-order functions for strings

| View in Tracker

Status/Resolution/Reason: To Test//Fixed

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

Created: 04/04/2017

Components: Language, Closures

Versions: 2016

Failure Type: Enhancement Request

Found In Build/Fixed In Build: CF 2016 /

Priority/Frequency: Normal /

Locale/System: / Platforms All

Vote Count: 2

Here's a usecase that came up today:

http://trycf.com/gist/4aceb6cc13cc6f9a6e73ffbad9d83012/acf2016?theme=monokai

```
<cfscript>
postcode = "E18 1ED";

nato = postcode.listToArray("").map(function(c){
	var natoWords = {
		"A": "Alfa",
		"B": "Bravo",
		"C": "Charlie",
		// etc
		"X": "X-ray",
		"Y": "Yankee",
		"Z": "Zulu"
	};
	return natoWords[c] ?: c;
});

writeOutput(nato.toList(""));

</cfscript>
```
This converts the string to an array and back. It's a god case for just being able to do:

```
writeOutput(postcode.map(function(c){ /* etc */});
```
"Needless" to say all the higher order functions ought to be implemented for strings. I'm not just suggesting implementing map.

Attachments:

Comments:

What this ticket is really asking for is for strings to be able to be treated as a character array like Java does. I'd be ok with this, but it should be a comprehensive thing IMO meaning all array operations should be valid on strings as well as syntax like so (which is already supported by Lucee Server) myString[ 3 ] which would return "S". Array member functions should work, all array functions should accept a string, and the higher order functions mentioned in this ticket should work.
Comment by Bradley W.
963 | April 04, 2017 04:04:15 PM GMT