在 F# List of List 中查找唯一记录

Find unique records in F# List of List

我有一条名为 Move 的记录,其定义如下:

type Move = {
X : int
Y : int
By: CellState }

我创建了一个移动列表 (Move list list) 来存储一些数据。我想从此列表中删除重复的条目。我示例中的每个子列表都具有相同的内容,但顺序不同。打印时看起来如下:

[[{X = 5;
   Y = 1;
   By = R;}; {X = 5;
              Y = 0;
              By = B;}; {X = 4;
                         Y = 0;
                         By = B;}]; [{X = 5;
                                      Y = 0;
                                      By = B;}; {X = 4;
                                                 Y = 0;
                                                 By = B;}; {X = 5;
                                                            Y = 1;
                                                            By = R;}];
 [{X = 4;
   Y = 0;
   By = B;}; {X = 5;
              Y = 1;
              By = R;}; {X = 5;
                         Y = 0;
                         By = B;}]]

此列表包含 3 个列表,每个列表有 3 条记录。每个列表都有相同的记录,但顺序不同。我想知道是否有办法从主列表中删除重复的子列表

如果您对子列表进行排序,那么 List.distinct 就可以了:

yourList 
|> List.map List.sort
|> List.distinct