Use foldLeft to avoid stack overflow for Gen.frequency with large list