You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Constructs and returns a list of type [`[System.Collections.Generic.HashSet[T]]`](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.hashset-1#remarks"See MS Docs about HashSet[T]") where `T` is the generic type defined through the `-GenericType` parameter (defaults to `[object]`).
80
+
81
+
This module makes utilizing a HashSet in PowerShell much easier through the use of "ScriptBlock equality comparers". With no pre-compiled or custom-defined `IEqualityComparer[T]` classes necessary, the `New-HashSet` cmdlet lets you define the equality comparison methods through normal PowerShell ScriptBlocks.
82
+
83
+
Let's say you are importing a CSV where many values of a specific column are duplicates and you only need the first one of each:
84
+
85
+
```csv
86
+
"Id", "Name", "Job"
87
+
"1", "John", "The Guy"
88
+
"1", "John", "The Guy?"
89
+
"2", "Jane", "[redacted]"
90
+
```
91
+
92
+
Using data like this, we can create a custom HashSet where as long as both the `Id` and `Name` columns are the same, the __entire__ object should be treated as the same.
93
+
94
+
```powershell
95
+
$csv = Import-Csv -Path .\Employees.csv
96
+
97
+
# The equality scriptblock must return a [bool] (true/false) value.
98
+
$equality = { # $left and $right -or- $x and $y -- must be used.
0 commit comments