Skip to content

Instantly share code, notes, and snippets.

@Nash0x7E2
Created October 8, 2019 15:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nash0x7E2/ec505e59cbc07fb7b6a88087eb09346d to your computer and use it in GitHub Desktop.
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.
/// 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