我有一组记录:
type Person =
{
Name : string
Age : int
}
let oldPeople =
set [ { Name = "The Doctor"; Age = 1500 };
{ Name = "Yoda"; Age = 900 } ]
与上面的硬编码示例不同,实际数据集来自一个数据源(我对其几乎没有控制权)。现在,我需要从另一个数据源中减去一组数据。通常,第二个源中的数据匹配,但偶尔会有大小写差异:
let peopleWhoAreConfusedAboutTheirAge =
set [ { Name = "THE DOCTOR"; Age = 1500 } ]
当我试图从第一个字符串集中减去第二个字符串集时,由于字符串比较是区分大小写的,所以失败了:
let peopleWhoKnowHowOldTheyAre =
oldPeople - peopleWhoAreConfusedAboutTheirAge
val peopleWhoKnowHowOldTheyAre : Set<Person> =
set [{Name = "The Doctor";
Age = 1500;}; {Name = "Yoda";
Age = 900;}]
有没有办法对People
记录的Name
字段进行不区分大小写的比较?
IComparable
实现即可满足原帖作者的要求。 - kaefer