Example.
I want to find the index of an item in an array.
After a google search and a browse of the Phobos
library, no luck!
Surely D must be an indexOf function that works on
arrays?
Something like...
string[] arr = ["pa", "db", "wb", "ha", "wa"];
int i = arr.indexOf("ha");
I eventually tried ChatGPT and abandoned it after
a number of failed attempts.
So I wrote my own function ...
size_t indexOf(string[] arr, string key) {
foreach (size_t i, val; arr)
if (val == key) return i;
return -1;
}
But, this is not satisfying. The Phobos library should
have this function.
I asked ChatGPT again with my example indexOf and it
came up with countUntil.
auto i = arr.countUntil("ha");
This seems to work but now I'm concerned.
Why was it so hard to find?
What is the best way to search for a function
in the Phobos library?