{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TupleSections #-}
module Data.Schedule
( Tick
, TickDelta
, Task
, TaskStatus(..)
, Schedule
, newSchedule
, checkValidity
, checkTask
, tickNow
, tickPrev
, ticksToIdle
, taskStatus
, after
, cancel
, cancel_
, renew
, whileJustM
, modST
, getST
, stA
, imodA
, getA
)
where
import Data.Schedule.Internal
whileJustM :: (Monad m, Monoid a) => m (Maybe a) -> m a
whileJustM act = go mempty
where
go accum = act >>= \case
Just r -> go (accum <> r)
Nothing -> pure accum
modST :: (s -> s) -> (s -> ((), s))
modST f s = ((), f s)
{-# INLINE modST #-}
getST :: (s -> o) -> (s -> (o, s))
getST f s = (f s, s)
{-# INLINE getST #-}
stA :: (s -> os) -> ((i, s) -> os)
stA f = f . snd
{-# INLINE stA #-}
imodA :: (i -> s -> s) -> ((i, s) -> ((), s))
imodA f = ((), ) . uncurry f
{-# INLINE imodA #-}
getA :: (s -> a) -> ((i, s) -> (a, s))
getA f = getST f . snd
{-# INLINE getA #-}