> * Whether or not contains() needs a comparison callback in my mind depends
> mainly on whether or not the operator overloading RFC passes. If it does,
> then contains() can/should use the __compareTo() method on objects. If it
> doesn't, then there needs to be some other way to compare non-identical
> objects or else that method becomes mostly useless.
This is only partly true. Let's say we have a vector of some complex
type A. There are legitimate reasons for using different ways of
comparing As, such as when projecting sub-fields (for example, sorting
by each member's name this time, but next time sorting by each
member's location).
Of course, if it passes, then using a type's built-in comparison
overloading is a sensible default, but it doesn't remove the need of
having a custom comparator.
-----
I was tired when I originally pointed it out the comparator/equatable
stuff, but Tyson was rightly saying that `any` solves this need, e.g.
<?php
if ($vec->contains($value, $eq)) {/**/}
// translates to
if ($vec->any(fn ($x) => $eq($x, $value))) {/**/}
?>
However, it's not as clear what to do for `indexOf` where you care
about the index it was found at.
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php