Skip to content

Instantly share code, notes, and snippets.

@ashphy
Created July 28, 2022 06:02
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 ashphy/0632504c85b979d3fc7e66685d287aac to your computer and use it in GitHub Desktop.
Save ashphy/0632504c85b979d3fc7e66685d287aac to your computer and use it in GitHub Desktop.
Map<T, int> uniqCount<T>(List<T> list) {
return list.fold<Map<T, int>>({}, (prev, element) {
prev.update(element, (value) => value + 1, ifAbsent: () => 1);
return prev;
});
}
void main() {
print(uniqCount([1, 1, 1, 2, 3, 4, 4, 5]));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment