tracker issue : CF-3534476

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

arraySearch()

| View in Tracker

Status/Resolution/Reason: To Fix//

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

Created: 04/02/2013

Components: Language

Versions: 10.0

Failure Type: Enhancement Request

Found In Build/Fixed In Build: Final /

Priority/Frequency: Trivial / Unknown

Locale/System: English / Platforms All

Vote Count: 3

ColdFusion as several different array-look-up functions which all do variations of the same thing:

* arrayContains()
* arrayFind()
* arrayFindNoCase()
* arrayFindAll()
* arrayFindAllNoCase()

What a mess. We don't need all of those, we just need one function:

integer function arraySearch(required Array arrayToSearch, required any objectToFind, optional String scope=(ONE|all), optional Boolean caseSensitive=TRUE)

I recommend deprecating that other mess of functions, and replacing with this one function.

-- 
Adam

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

Watson Bug ID:	3534476

External Customer Info:
External Company:  
External Customer Name: Adam Cameron.
External Customer Email:  
External Test Config: My Hardware and Environment details:

Attachments:

Comments:

Would be nice to manage one function and have one source of reference instead of multiple ones that do basically the same thing.
Vote by External U.
15842 | April 03, 2013 12:14:08 PM GMT
Embrace Simplicity... eschew obfuscation!
Vote by External U.
15843 | June 05, 2013 08:07:09 AM GMT
I am all for simplifying this and it should have been like this to begin with. However, now that these functions have been around for a while and so commonly used, would it make sense to deprecate them?
Comment by Rupesh K.
15838 | May 02, 2014 07:45:49 PM GMT
You do understand that *deprecating* something basically just means adding advice to the docs that they're not longer the favoured way of doing something, and advise the user to use the new way, right? It does't actually impact the operational status of the deprecated functionality at all? Consider parameterExists() as an example. Deprecated for over a decade now. Still works. -- Adam
Comment by External U.
15839 | May 03, 2014 03:04:47 AM GMT
+1 - ArrayFindNoCase() and ArrayFindAllNoCase() (and their member function equivalents) always return an empty array when the 2nd parameter is a function (#CF-3228672), so those don't even work as documented. I'd just use ArraySearch() :)
Vote by External U.
15844 | May 08, 2014 12:21:39 PM GMT
Regarding my comment in my vote: That's only true if the array doesn't contain the function that's being searched for. Basically, if the second parameter is a function, ArrayFind()/ArrayFindAll() executes the function for each element in the array and ArrayFindNoCase()/ArrayFindAllNoCase() searches the array for the function. Interesting. So should arraySearch() also then have another parameter that toggles how its second parameter is treated when it is a function? Thanks!, -Aaron
Comment by External U.
15840 | May 12, 2014 08:49:24 AM GMT
Hi Adam and Adobe, I'd like to suggest the return type be array, even if 1 result, just like other functions in CF (ex: reMatch / structFindKey / structFindValue). Thanks!, -Aaron
Comment by Aaron N.
15841 | February 18, 2018 10:10:40 PM GMT