WordSet getWords(string filename, int wordsize) { WordSet words; File(filename).byLine .map!(line => line.until!(not!isAlpha)) .filter!(word => word.count == wordsize) .each!(word => words[word.to!string.toUpper] = 0); return words; }
This is also 4x faster than my version that used a regex -- thanks!
Why did you use string.count rather than string.length?