I need to create a distinct list of history items from multiple sources, where the most recent item is the one kept. I'm trying something like this but because of the problem domain it is not simple to check that the result is accurate.
Function GetUnique {
param( $source1, $source2, ...)
$items = $source1 + $source2 + ...;
$unique = $items | Sort-Object -Desc -Unique -Prop Timestamp;
# Does this contain the most recent items?
$unique;
}
I'm reasonably surprised there is no -Stable switch to indicate the preference.
Note: I'm aware that even if the sort is stable, I'm making an assumption about the uniqueness algorithm. If the sort is stable, I can write my own stable Get-Unique commandlet relatively easily that assumes stable sorted input. However, I don't really want to implement MergeSort.