Stateful function. Almost like reduce, but for repeated calls to a function instead of elements in a list.