module Data.EventList.Relative.BodyTime
(T, mapM, empty,
fromPairList, toPairList,
cons, snoc, viewL, viewR,
) where
import Data.EventList.Relative.BodyTimePrivate
import qualified Data.AlternatingList.List.Disparate as Disp
import Data.EventList.Utility (mapFst, mapSnd, )
import Prelude hiding
(mapM)
mapM :: Monad m =>
(time0 -> m time1) -> (body0 -> m body1) ->
T time0 body0 -> m (T time1 body1)
mapM timeAction bodyAction =
liftM (Disp.mapM bodyAction timeAction)
fromPairList :: [(body, time)] -> T time body
fromPairList = Cons . Disp.fromPairList
toPairList :: T time body -> [(body, time)]
toPairList = Disp.toPairList . decons
empty :: T time body
empty = Cons Disp.empty
cons :: body -> time -> T time body -> T time body
cons body time = lift (Disp.cons body time)
snoc :: T time body -> body -> time -> T time body
snoc xs body time =
Cons $ (Disp.snoc $*~ xs) body time
viewL :: T time body -> Maybe ((body, time), T time body)
viewL = fmap (mapSnd Cons) . Disp.viewL . decons
viewR :: T time body -> Maybe (T time body, (body, time))
viewR = fmap (mapFst Cons) . Disp.viewR . decons