Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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