Skip to content
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

Equality and Comparisons #3

Closed
dyslexicanaboko opened this issue Sep 5, 2023 · 1 comment · Fixed by #8
Closed

Equality and Comparisons #3

dyslexicanaboko opened this issue Sep 5, 2023 · 1 comment · Fixed by #8
Labels
enhancement New feature or request

Comments

@dyslexicanaboko
Copy link
Owner

Handling equality and comparisons for List<T>

  • Modify List<T> constructor to give an optional way to provide a IComparer of T or equivalent for the following functions:
    • contains(item: T): boolean
      • This function will operate based on how equality and comparison is implemented in T
    • removes(item: T): boolean
      • Works like contains
    • sort(comparison?: (left: T, right: T) => number): void
      • This function will operate based on how equality and comparison is implemented in T or the user can provide their own sort function. As of right now a default comparer is inside of the class, but it will only work for primitives.

Handling equality and comparisons for non-primitive types

Unanswered questions

  • Can TypeScript handle complex objects of type T providing guidance on equality and comparison?
  • Can the List<T> automatically pick up how to compare complex T from T?
    • If yes, then great, that's how C# does it.
    • If no, then that kind of sucks, but the constructor can just take an optional comparer object
@dyslexicanaboko dyslexicanaboko added the enhancement New feature or request label Sep 5, 2023
This was referenced Sep 5, 2023
@dyslexicanaboko
Copy link
Owner Author

Ran into some interesting bumps for this one. The getHashCode() function is not implemented yet, but will be in #4. I have implemented IEquatable<T> and IComparable<T>.

dyslexicanaboko added a commit that referenced this issue Sep 10, 2023
* 3 I was not aware that JavaScript has properties now! I just updated all of my methods that were stand ins for properties into read-only properties in most cases. This is excellent news.

* 3 Performing renames on files to make room for new concepts. Checking in the Complex tests broken in preparation to start filling them out.

* 3 Cleaned up the test copy and removed what wasn't needed for testing. Changed all numbers to ComparableObjects.

* 3 Tests are still failing, but progress made on testing if an item T has implemented an equals function or not.

* 3 Moved files according to their would be dot net framework locations because why not at this point. Fixed multiple tests. Fixed a few bugs. Moved on to implementing IComparable of T.

* 3 Implemented IComparable<T> compareTo and updated all tests to handle the folder changes. All List of T tests now pass.

* 3 Implemented the distinct() function and a unit test for it. That wrap this ticket up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant