| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Data.Timers
- foldrOnce :: (a -> b -> a) -> (a, [b]) -> (a, [b])
- foldrTimes :: (a -> b -> a) -> (a, [b]) -> Int -> (a, [b])
- foldlOnce :: (a -> b -> b) -> ([a], b) -> ([a], b)
- foldlTimes :: (a -> b -> b) -> ([a], b) -> Int -> ([a], b)
- foldrOnceM :: Monad m => (a -> b -> a) -> (a, [b]) -> m (a, [b])
- foldrTimesM :: Monad m => (t -> t1 -> t) -> (t, [t1]) -> Int -> m (t, [t1])
- foldlOnceM :: Monad m => (t1 -> t -> t) -> ([t1], t) -> m ([t1], t)
- foldlTimesM :: Monad m => (t1 -> t -> t) -> ([t1], t) -> Int -> m ([t1], t)
- nest :: (b -> b) -> b -> Int -> b
- nestM :: Monad m => (b -> m b) -> b -> Int -> m b
- nestByM :: Monad m => (b -> m b) -> b -> m Int -> m b
- nestMForever :: Monad m => (b -> m b) -> b -> m b
- nestByOrd :: (a -> Ordering) -> (a -> a) -> (a -> a) -> a -> a
- switchByPred :: (t1 -> t) -> (t1 -> t) -> (t1 -> Bool) -> t1 -> t
- switchOnM :: (Monad m, Monad m1) => (b -> m1 b) -> (m1 b -> m b) -> m1 Int -> b -> m b
- switchEveryN :: Monad m => (b -> b) -> (b -> m b) -> Int -> b -> m b
- switchEveryM :: Int -> Int -> (a -> IO a) -> (a -> IO a) -> a -> IO Void
- fixPt :: Eq a => (a -> a) -> a -> a
- printEveryN :: Show b => (b -> b) -> Int -> b -> IO b
- sideEffectEveryN :: Monad m => (b -> m a) -> (b -> b) -> Int -> b -> m b
- switchEvery' :: (UTCTime, Integer, Int, IO t5 -> IO (IO t5), t5 -> IO (IO t5), IO t5) -> IO (UTCTime, Integer, Int, IO t5 -> IO (IO t5), t5 -> IO (IO t5), IO t5)
- switchEvery'' :: (Integral t4, Integral t6) => (UTCTime, t6, t4, t7 -> IO t7, t5 -> IO t7, IO t5) -> IO (UTCTime, t6, Int, t7 -> IO t7, t5 -> IO t7, t7)
Documentation
foldrOnce :: (a -> b -> a) -> (a, [b]) -> (a, [b]) Source #
foldrOnce applies a right fold, only once (for streams, primarily).
foldrTimes :: (a -> b -> a) -> (a, [b]) -> Int -> (a, [b]) Source #
foldrTimes applies foldrOnce a given number of times.
foldlTimes :: (a -> b -> b) -> ([a], b) -> Int -> ([a], b) Source #
See foldlOnce, foldrTimes.
foldrOnceM :: Monad m => (a -> b -> a) -> (a, [b]) -> m (a, [b]) Source #
foldrOnceM generalizes foldrOnceM to general monads.
foldrTimesM :: Monad m => (t -> t1 -> t) -> (t, [t1]) -> Int -> m (t, [t1]) Source #
See foldrOnceM, foldrTimes.
foldlOnceM :: Monad m => (t1 -> t -> t) -> ([t1], t) -> m ([t1], t) Source #
See foldrOnceM, foldlOnce.
foldlTimesM :: Monad m => (t1 -> t -> t) -> ([t1], t) -> Int -> m ([t1], t) Source #
See foldrTimesM, foldlOnceM,
nestMForever :: Monad m => (b -> m b) -> b -> m b Source #
nestMForever is equivalent to `nestM f x Infinity`.
λ> nestMForever (x -> print x >> return x) (return 10 :: Expire Int)
Expire {getExpire = (1,Just 10)}
Expire {getExpire = (1,Just 10)}
Expire {getExpire = (1,Just 10)}
Expire {getExpire = (1,Just 10)}
Expire {getExpire = (1,Just 10)}
Expire {getExpire = (1,Just 10)}
Expire {getExpire = (1,Just 10)}
Expire {getExpire = (1,Just 10)}
Expire {getExpire = (1,Just 10)}
Expire {ge^Cpire = (1,Just 10)}
Expire {getExpire = (1,Just 10)}
Expire {getExpireInterrupted.
λ> nestMForever (x -> print x >> return x) (return 10 :: ExpireE Int)
ExpireE {getExpireE = (1,10)}
ExpireE {getExpireE = (1,10)}
ExpireE {getExpireE = (1,10)}
ExpireE {getExpireE = (1,10)}
ExpireE {getExpireE = (1,10)}
Ex^CE {getExpireE = (1,10)}
ExpireE {getExpireE = (1,10)}
ExpireE {getExpireE = (1,10)}Interrupted.
λ> dumpExpireIO == print) >> return x) (return 10 :: ExpireIO Int) J^Cust (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1Interrupted.
λ> dumpExpireIO == print >> killExpireIO x) >> return x) (return 10 :: ExpireIO Int) Just^Cust (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10Interrupted.
λ> dumpExpireIO == print) >> return x) (return 10 :: ExpireIO Int) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Just (1,10) Jus^Ct (1,10) JusInterrupted. Real Mem: 157.4 MB See `stable_infinite_ExpireIO_loop_sample.txt` for a sample
nestByOrd :: (a -> Ordering) -> (a -> a) -> (a -> a) -> a -> a Source #
This function assumes that applying f too many times is fine, it tries to apply f just enough times to hit EQ, then applies g and repeats forever
switchByPred :: (t1 -> t) -> (t1 -> t) -> (t1 -> Bool) -> t1 -> t Source #
switchByPred returns `f x` if `p x` else `g x`.
switchOnM :: (Monad m, Monad m1) => (b -> m1 b) -> (m1 b -> m b) -> m1 Int -> b -> m b Source #
switchOnM is to switchEveryN as nestByM is to nestM.
switchEveryN :: Monad m => (b -> b) -> (b -> m b) -> Int -> b -> m b Source #
switchEveryN applies f, n times, then g once, then repeats forever.
switchEveryM :: Int -> Int -> (a -> IO a) -> (a -> IO a) -> a -> IO Void Source #
Seconds taken to be in [1..59]. This returns fElse of the input if the clock time's minutes == minutes, otherwise f x.
Note that this function results in an infinite loop (which is why it has a return type of Void).
fixPt :: Eq a => (a -> a) -> a -> a Source #
fixPt gives the fixed point of f on x.
Compare its type to that of fix:
fix :: (a -> a) -> a
This fixed-point stops at equality, e.g. 1, 2, 3, 3, a.. -> 1, 2, 3.
printEveryN :: Show b => (b -> b) -> Int -> b -> IO b Source #
Nest the function the given number of times, on the given value, printing every iteration
f n x -> (mapM_ print . take n . iterate f) x >> return (nest f n x)
sideEffectEveryN :: Monad m => (b -> m a) -> (b -> b) -> Int -> b -> m b Source #
Nest the function the given number of times, on the given value, resulting in the given side-effect every iteration
s f n x -> (mapM_ s . take n . iterate f) x >> return (nest f n x)