且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何删除 Dart 列表中的重复项?list.distinct()?

更新时间:2023-02-13 16:39:03

我有一个名为 Reactive-Dart 包含许多用于终止和非终止序列的可组合运算符.对于您的场景,它看起来像这样:

I have a library called Reactive-Dart that contains many composable operators for terminating and non-terminating sequences. For your scenario it would look something like this:

final newList = [];
Observable
   .fromList(['abc', 'abc', 'def'])
   .distinct()
   .observe((next) => newList.add(next), () => print(newList));

产量:

[abc, def]

我应该补充一点,还有其他具有类似功能的库.在 GitHub 上四处看看,我相信你会找到合适的.

I should add that there are other libraries out there with similar features. Check around on GitHub and I'm sure you'll find something suitable.