Created
October 8, 2019 15:28
-
-
Save Nash0x7E2/ec505e59cbc07fb7b6a88087eb09346d to your computer and use it in GitHub Desktop.
Filters the duplicate items from both list. Returns a new list of type T unique items.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Mixin containing a helper list method | |
mixin ListDistinct { | |
/// Creates a new list with the unique elements form [listOne] and [listTwo]. | |
/// The new list is returned with the specified type [T] | |
List<T> distinct<T>(List<T> listOne, List<T> listTwo) { | |
final List<T> _newList = <T>[]; | |
_newList.addAll(listOne); | |
for (final T item in listTwo) { | |
if (_newList.contains(item)) { | |
_newList.remove(item); | |
} | |
_newList.add(item); | |
} | |
return _newList; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment