-
-
Notifications
You must be signed in to change notification settings - Fork 22k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add more array methods: find_custom
, rfind_custom
#80208
Conversation
Please fix the message of your commit |
These need to be added to the binds for them to be useful in scripting
|
first_custom
, last_custom
, count_custom
core/variant/array.cpp
Outdated
@@ -353,6 +353,36 @@ int Array::find(const Variant &p_value, int p_from) const { | |||
return ret; | |||
} | |||
|
|||
int Array::first_custom(const Callable& p_callable, int p_from = 0) const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name feels misleading, using first
makes it sound like it returns that value, not the index, just like suggested on the previous PR I'd say find_custom
and rfind_custom
You're right, I didn't think about using reduce in that way. I can remove that. Should I rename |
I think it should be
godot/core/variant/variant_call.cpp Lines 2204 to 2208 in 237bd0a
Don't forget the docs (XML files in the Also, you should consider adding tests for the methods. |
How would I create a callable for the tests? I don't see precedent for this, though I could be missing something. |
I think you can use godot/tests/core/object/test_object.h Line 351 in 237bd0a
or godot/tests/core/threads/test_worker_thread_pool.h Lines 46 to 48 in 237bd0a
|
Or add it as a gdscript test under |
I think it's less preferable, GDScript tests are for testing the GDScript implementation, not the core. |
Ah, so I can use a c++ function as a callable? |
Yes. |
I hope I amended it correctly. |
first_custom
, last_custom
, count_custom
find_custom
, rfind_custom
Please also make sure that the commit message refers to the actual names of the methods. Personally, I agree that these should be variants of |
Fixed typo and comment style nitpick. |
If there's any more changes that need be made, I will address them tomorrow, as it is 3:30 in the morning and my brain is shutting down. |
The method documentation should include that the |
Resolved typos and style checks from @AThousandShips . |
Whoops, I messed up the test. That's what I get for having nvim in a thin window where I can't see the whole line. |
You still need to amend the commit message to reflect what the methods are actually called. |
nice catch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good save for some corrections to the documentation and style
Integrated the changes, @AThousandShips . |
Turns out there's already a PR for this change, predating it: But this one is more refined IMO |
oh dear, I'm not sure i updated the documentation for the other function... Will the checks need to be run again? |
They do, but no worries just go ahead and fix them |
This one is exactly same as #73490 minus naming with an exception that the other one has much more comprehensive test suite. |
So is mine redundant? |
Will be a decision which one to merge |
Changed semantics on rfind_custom(). |
|
Added 3 new array functions -
count_custom
,first_custom
, andlast_custom
. These perform the functions of the existingcount,
,first
, andrfind
respectively, but using a Callable as the conditions, likesort_custom
.Last could be renamed
rfind_custom
for consistency sake.