I find generators useful when I want to avoid intermediate results. However, when the transformation is already wrapped in a function,
(f(x) for x in xs)
feels redundant. Is there a “standard” way to use a function like in map
, but get a generator? Or should I just define something like
"""Return a generator mapping the elements of `c` using `f`."""
mapgen(f, c) = (f(x) for x in c)