You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While this function is useful, it leaves something to be desired from the caller's perspective. Namely: where is it?
To answer this valuable question, the caller will then have to traverse the array themselves and find the thing they know is in there (and just got found! <- this is repeated work, right?)
Suggested Solution
The act of determining does this array contain that thing, is nothing more than a return-type change away from where is this thing in that array?
Arguably this function is a superset of both implementations:
indexOf(thing: T): UInt64? {
if (!contains(thing)) {
// find its index and return it
}
// return nil // "contains = false"
}
The text was updated successfully, but these errors were encountered:
Thank you for your feature request! There hasn't been much effort on the standard library yet. This should be easy to add, pull requests are very welcome! Like you pointed out, it would be very similar to the contains function.
Issue To Be Solved
Arrays in Cadence have a limited API, but they do feature the function contains.
https://docs.onflow.org/cadence/language/values-and-types/#array-fields-and-functions
While this function is useful, it leaves something to be desired from the caller's perspective. Namely: where is it?
To answer this valuable question, the caller will then have to traverse the array themselves and find the thing they know is in there (and just got found! <- this is repeated work, right?)
Suggested Solution
The act of determining does this array contain that thing, is nothing more than a return-type change away from where is this thing in that array?
Arguably this function is a superset of both implementations:
The text was updated successfully, but these errors were encountered: