-
-
Notifications
You must be signed in to change notification settings - Fork 444
Closed
Description
Hi!
When you use the collection initializer of a HashSet you end up with an empty HashSet, which I guess is the case because it is an immutable collection, but since I am creating the collection at that point in time and not modifying it after creation I was surprised to see my HashSet was empty. The thing is that this compiles just fine but at runtime the HashSet is empty. Below a comparison between the System and LangExt versions of the type:
using System.Collections.Generic;
using Shouldly;
using Xunit;
namespace Tests;
public class HashSetTest
{
private static readonly LanguageExt.HashSet<string> HashSetLangExt =
new()
{
"value1",
"value2",
"value3"
};
private static readonly HashSet<string> HashSetSystem =
new()
{
"value1",
"value2",
"value3"
};
[Fact]
public void LangExt_ShouldContainItems() => HashSetLangExt.ShouldNotBeEmpty(); // False
[Fact]
public void System_ShouldContainItems() => HashSetSystem.ShouldNotBeEmpty(); // True
}I don't know if this is intended behavior or a bug, but it sure is confusing :P
(running the latest version of LangExt btw)
Metadata
Metadata
Assignees
Labels
No labels