iterateN package:diagrams-lib

iterateN n f x returns the list of the first n iterates of f starting at x, that is, the list [x, f x, f (f x), ...] of length n. (Note that the last element of the list will be f applied to x (n-1) times.)