| Copyright | (C) 2018 Francesco Ariis |
|---|---|
| License | BSD3 (see LICENSE file) |
| Maintainer | Francesco Ariis <fa-ml@ariis.it> |
| Stability | provisional |
| Portability | portable |
| Safe Haskell | Safe |
| Language | Haskell2010 |
Control.Timer.Tick
Description
Timers and timed resources (animations, etc.) utilities for tick-based programs.
- creaTimer :: Integer -> Timer
- type Timer = TimedRes ()
- data TimedRes a
- creaTimedRes :: Loop -> [(Integer, a)] -> TimedRes a
- data Loop
- tick :: TimedRes a -> TimedRes a
- ticks :: Integer -> TimedRes a -> TimedRes a
- reset :: TimedRes a -> TimedRes a
- isLive :: TimedRes a -> Bool
- isExpired :: TimedRes a -> Bool
- fetch :: TimedRes a -> a
Simple timers
creaTimer :: Integer -> Timer Source #
Creates a Timer expiring in x ticks.
Example:
main = count (creaTimer 4)
where
count t | isExpired t = putStrLn "Over!"
| otherwise = do putStrLn "Ticking."
count (tick t)
-- λ> main
-- Ticking.
-- Ticking.
-- Ticking.
-- Ticking.
-- Over!
Timed Resources
A timed resource is a timer which, at any given moment, points to a specific item (like an animation).
Example:
run = creaTimedRes (Times 1) [(2, "a "), (1, "b "), (2, "c ")]
main = count run
where
count t | isExpired t = putStrLn "nOver!"
| otherwise = do putStr (fetch t)
count (tick t)
-- λ> main
-- a a b c c
-- Over!
creaTimedRes :: Loop -> [(Integer, a)] -> TimedRes a Source #
Creates a time-based resource, like an animation.
Number of times to repeat the animation.
Constructors
| Times Integer | |
| AlwaysLoop |