Open nmunday opened 3 years ago
It's true that prelude-ts is currently more geared towards objects. Maybe we could add such a feature, depending on how much change would have to be done to the implementation. I'm guessing it wouldn't be too bad, but I don't plan on investing time on this soon.
Maybe you could leverage javascript's prototype nature.. https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object_prototypes I didn't think about it too much though.
Sorry for the delay to answer...
I think this means that Sets that require custom equality or hash code generation can only be used with classes and methods and not simple objects (for example number[])?
Yes, you shouldn't put things like plain arrays. This is covered in the docs: https://github.com/emmanueltouzery/prelude-ts/wiki/Prelude%E2%88%92ts-user-guide#equality
It wouldn't compile in typescript and should throw in JavaScript.
There maybe a way already to allow this. I would like to be able to use interfaces for the elements. At the moment I believe that would mean having equals and hashCode on the interface which would then mean creating an instance of the interface would require setting those each time.
If the collection implementations could take an EqualityComparer which has those 2 methods then I believe I could use interfaces.
Another advantage is that I could then have different Equality for the same interface. My main Interface is:
interface Fact { subject: string, property: string , value: string }
Depending on the circumstance any of the properties could be the key or any combination also.
Thanks.