class WordCount { Map countWords(String input) { var exp = new RegExp(r"(\w+('\w+)?)"); return exp .allMatches(input) .map((e) => e.group(0)!.toLowerCase()) .fold(new Map(), (Map counts, String word) { if (counts.containsKey(word)) { counts[word] = counts[word]! + 1; } else { counts[word] = 1; } return counts; }); } }