HashSet constructor IEnumerable / fixing distinct check #277
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
I think there is a bug in internal constructor for Set/HashSet with
checkUniqueness
. You pass this totryAdd
. I think tryAdd will ignore duplicates, so probably a negation missing. This commit contains a fix.Seems you use this constructor only for Bind when creating new sets. I changed the name of checkUniqueness to tryAdd and negated the values there. IMHO this makes it more clear because everything is now "tryAdd". But perhaps you don't like this way... then you probably have to add "!" in constructor code before calling Internal constructor like
new SetInternal<OrdDefault<A>, A>(items, !checkForUniqueness)
to just fix the bug.I splitted HashSet constructor function the same way it is splitted for Set. I didn't really verify this but I guess the errors I get when deserializing json are due to a "missing" constructor with only
IEnumerable<T>
as arg. (It's working for Set.)At least this makes Set and HashSet same style.
Side note: I switched my code from Set to HashSet because I noticed some "strange" behaviour when comparing my sets. The cause was that I have Sets of a
Record<T>
with[OptOutOfEq]
and customEquals
-- but Set equality comparison (and especiallyContains
) uses Ord. This is not a bug in LanguageExt, but reminded me that Set can only be used with types that have valid Ordering. I just need Equality for my use case so that's all I want to implement.