Map<T, int> frequency() { Map<T, int> f = {}; for (T item in this) { if (!f.containsKey(item)) f[item] = 0; f[item] = f[item]! + 1; } return f; }