Last active
November 9, 2019 15:08
-
-
Save phanirithvij/a3a4160140584285b31189654aa59ab2 to your computer and use it in GitHub Desktop.
A dart example to remove duplicate objects by a particular field
This file contains 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
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