Skip to content

Commit

Permalink
[chore] move lazy &&~ and lazy ||~ to App module
Browse files Browse the repository at this point in the history
  • Loading branch information
MangoIV committed Apr 10, 2024
1 parent 70bc121 commit f9cb4e6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
24 changes: 0 additions & 24 deletions integration/test/Notifications.hs
Original file line number Diff line number Diff line change
Expand Up @@ -195,30 +195,6 @@ isConnectionNotif status n =
nPayload n %. "type" `isEqual` "user.connection"
&&~ nPayload n %. "connection.status" `isEqual` status

-- | make Bool lazy
liftBool :: Functor f => f Bool -> BoolT f
liftBool = MaybeT . fmap (bool Nothing (Just ()))

-- | make Bool strict
unliftBool :: Functor f => BoolT f -> f Bool
unliftBool = fmap isJust . runMaybeT

-- | lazy (&&)
(&&~) :: App Bool -> App Bool -> App Bool
b1 &&~ b2 = unliftBool $ liftBool b1 *> liftBool b2

infixr 3 &&~

-- | lazy (||)
(||~) :: App Bool -> App Bool -> App Bool
b1 ||~ b2 = unliftBool $ liftBool b1 <|> liftBool b2

infixr 2 ||~

-- | lazy (&&): (*>)
-- lazy (||): (<|>)
type BoolT f = MaybeT f ()

assertLeaveNotification ::
( HasCallStack,
MakesValue fromUser,
Expand Down
28 changes: 28 additions & 0 deletions integration/test/Testlib/App.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
module Testlib.App where

import Control.Applicative ((<|>))
import Control.Monad.Reader
import Control.Monad.Trans.Maybe (MaybeT (MaybeT), runMaybeT)
import qualified Control.Retry as Retry
import Data.Aeson hiding ((.=))
import Data.Bool (bool)
import Data.IORef
import Data.Maybe (isJust)
import qualified Data.Text as T
import qualified Data.Yaml as Yaml
import GHC.Exception
Expand Down Expand Up @@ -72,3 +76,27 @@ instance MakesValue FedDomain where
-- backwards-compatible way so everybody can benefit.
retryT :: App a -> App a
retryT action = Retry.recoverAll (Retry.exponentialBackoff 8000 <> Retry.limitRetries 10) (const action)

-- | make Bool lazy
liftBool :: Functor f => f Bool -> BoolT f
liftBool = MaybeT . fmap (bool Nothing (Just ()))

-- | make Bool strict
unliftBool :: Functor f => BoolT f -> f Bool
unliftBool = fmap isJust . runMaybeT

-- | lazy (&&)
(&&~) :: App Bool -> App Bool -> App Bool
b1 &&~ b2 = unliftBool $ liftBool b1 *> liftBool b2

infixr 3 &&~

-- | lazy (||)
(||~) :: App Bool -> App Bool -> App Bool
b1 ||~ b2 = unliftBool $ liftBool b1 <|> liftBool b2

infixr 2 ||~

-- | lazy (&&): (*>)
-- lazy (||): (<|>)
type BoolT f = MaybeT f ()

0 comments on commit f9cb4e6

Please sign in to comment.