Skip to content

Instantly share code, notes, and snippets.

@phanirithvij
Last active November 9, 2019 15:08
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 phanirithvij/a3a4160140584285b31189654aa59ab2 to your computer and use it in GitHub Desktop.
Save phanirithvij/a3a4160140584285b31189654aa59ab2 to your computer and use it in GitHub Desktop.
A dart example to remove duplicate objects by a particular field
class Person{
final String name;
const Person(this.name);
toString(){
return "Person Object $name";
}
}
void main() {
final people = [Person("Joe"), Person("Mary"), Person("Mary")];
final existing = Set<String>();
final unique = people
.where((person) => existing.add(person.name))
.toList();
print(unique);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment