{-# LANGUAGE TemplateHaskell #-}
module Wire.Sem.Now
( Now (..),
get,
boolTTL,
)
where
import Data.Time.Clock
import Imports
import Polysemy
import Polysemy.Check (deriveGenericK)
import Wire.Sem.FromUTC
data Now m a where
Get :: Now m UTCTime
makeSem ''Now
deriveGenericK ''Now
deriving instance Show (Now m a)
boolTTL ::
forall t r a.
(Member Now r, Ord t, FromUTC t) =>
a ->
a ->
t ->
Sem r a
boolTTL :: forall t (r :: EffectRow) a.
(Member Now r, Ord t, FromUTC t) =>
a -> a -> t -> Sem r a
boolTTL a
f a
t t
time = do
t
now <- UTCTime -> t
forall a. FromUTC a => UTCTime -> a
fromUTCTime (UTCTime -> t) -> Sem r UTCTime -> Sem r t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Sem r UTCTime
forall (r :: EffectRow). Member Now r => Sem r UTCTime
get
a -> Sem r a
forall a. a -> Sem r a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> Sem r a) -> a -> Sem r a
forall a b. (a -> b) -> a -> b
$ a -> a -> Bool -> a
forall a. a -> a -> Bool -> a
bool a
f a
t (Bool -> a) -> Bool -> a
forall a b. (a -> b) -> a -> b
$ t
now t -> t -> Bool
forall a. Ord a => a -> a -> Bool
<= t
time