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
Testing for Equality #172
Comments
Would an extension of |
Sadly the |
It is unfortunate that we do have a base equals method. I think checking for an exists function and calling it is a reasonable idea, can't see why not. |
This works just fine for me: <?php declare(strict_types = 1);
namespace App\Library\Enum;
use Ds\Hashable;
use MyCLabs\Enum\Enum as BaseEnum;
/**
* @psalm-immutable
* @extends BaseEnum<string>
*/
abstract class Enum extends BaseEnum implements Hashable
{
public function hash(): string
{
return $this->getValue();
}
} The point is you don't need to override the That said I do agree that being able to provide a custom equality function could be beneficial in some cases. It's not necessary for MyCLabs enums though. |
I would like to posit an idea based on this statement from the docs in Map:
Would it be possible to test for any
equals
function and at least try it? What's my use case I hear you ask...I use
MyClabs\Enum\Enum
a lot, at least I did until I started usingDS
a lot more. Now I have had to re-implement a library for Enum because I need it for keys in Maps, and I can't reliably useMyClabs\Enum\Enum
as it doesn't implementHashable
.It's ok I suppose to use my implementation, but I would rather not have to so that I can take easy advantage of updates and fixes.
I'm copying in @benjaminbertin, @valentin-claras and @mnapoli as the MyClabs team, as maybe there may be a way they'd consider supporting Ds somehow.
The text was updated successfully, but these errors were encountered: