G’day:
I just raised this: Implement iteration/collection methods for strings. This was off the back of Igal mentioning a desire to be able to treat a string as a collection of characters during the for(element in list)
discussion on the main Lucee forum.
The content of the ticket states (somewhat tersely):
IE: String.each()
, String.map()
, String.reduce()
(and sort()
, filter()
, some()
, every()
, the whole lot) which treat the string as a collection of characters.
I just thought I’d mention it here too by way of trying to liven the place up.
–
Adam
Looks to me like these have been implemented. They certainly need documenting and thorough testing though (I don’t have time right now to go through them all thoroughly). Example:
Use Lucee 4.5/5 engine, naturally.
Oh dear.
Yeah, it looks like they’ve been implemented for lists. EG: you’ve specified a space delimiter there, so it treats “my string” as a two-element list. What it should be doing is treating it like a nine character string.
If a method is supposed to treat the string as a list, then the method should mention “list” in its name. Otherwise it should be considered a string method, without imparting any special handling of the string (eg: it’s a delimited list).
We went round the houses on this same issue with CF, so it might be worth taking Tracker as a starting point for possibly “fixing” this.
I’ll raise a ticket equivalent to that one for you guys… [LDEV-388] - Lucee
Cheers.
–
Adam