This version uses map and generators.