Skip to content

Instantly share code, notes, and snippets.

@fritz0705
Last active August 29, 2015 14:21
Show Gist options
  • Save fritz0705/2438f7268bdb6aabca29 to your computer and use it in GitHub Desktop.
Save fritz0705/2438f7268bdb6aabca29 to your computer and use it in GitHub Desktop.
import Data.Foldable (fold)
import Data.Monoid (Endo(Endo, appEndo))
-- | @replicateEndo n f@ replicates n times an endomorphism f and folds them using
-- function composition to an endomorphism @a -> a@.
--
-- Propositions:
-- > replicateEndo _ id == id
-- > replicateEndo _ (const x) == const x
-- > replicateEndo 0 _ == id
replicateEndo :: Int -> (a -> a) -> a -> a
replicateEndo n = appEndo.fold.replicate n.Endo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment