{-# LANGUAGE BangPatterns #-}

module Data.Function.Utils
    ( applyN
    ) where

import Prelude

-- | Apply a function 'n' times to the specified input.
applyN :: Integral n => n -> (a -> a) -> a -> a
applyN :: n -> (a -> a) -> a -> a
applyN !n
n !a -> a
f !a
a
    | n
n n -> n -> Bool
forall a. Ord a => a -> a -> Bool
<= n
0 = a
a
    | Bool
otherwise = n -> (a -> a) -> a -> a
forall n a. Integral n => n -> (a -> a) -> a -> a
applyN (n
n n -> n -> n
forall a. Num a => a -> a -> a
- n
1) a -> a
f (a -> a
f a
a)