How to delete duplicates in a dart List? list.distinct()?

后端 未结 11 2123
夕颜
夕颜 2020-12-01 05:21

How do i delete duplicates from a list without fooling around with a set? Is there something like list.distinct()? or list.unique()?

void main() {
  print(\"         


        
11条回答
  •  清歌不尽
    2020-12-01 05:23

    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));
    

    Yielding:

    [abc, def]
    

    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.

提交回复
热议问题