#Haskell question: Is there a function for "reapply this function to a starting value N times"? e.g. `doTimes (*2) 3 1` would return `8` ((*2) $ (*2) $ (*2) $ 1). I know I could chain take and iterate and then do a Data.List.last, but that has crumby performance for very large values of N.

Reply to this note

Please Login to reply.

Discussion

isnt this just:

doTimes f n x = foldl’ (\acc _ -> f acc) x [1..n]