Derive a few Semigroup+Monoid instances

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3717
GitOrigin-RevId: 9bc7f64754a8461a006d9b633a712124f828166e
This commit is contained in:
Auke Booij 2022-02-18 15:57:09 +01:00 committed by hasura-bot
parent 5541ec011e
commit 557a3d4b6e
4 changed files with 13 additions and 28 deletions

View File

@ -319,13 +319,7 @@ instance NFData JoinSource
newtype Where
= Where [Expression]
deriving (NFData, Eq, Ord, Show, Generic, Data, Lift, FromJSON, Hashable, Cacheable)
instance Monoid Where where
mempty = Where mempty
instance Semigroup Where where
(Where x) <> (Where y) = Where (x <> y)
deriving (NFData, Eq, Ord, Show, Generic, Data, Lift, FromJSON, Hashable, Cacheable, Semigroup, Monoid)
data Cardinality
= Many

View File

@ -233,11 +233,9 @@ instance FromJSON n => FromJSON (Countable n)
deriving instance Ord ColumnName
instance Monoid Where where
mempty = Where mempty
deriving instance Monoid Where
instance Semigroup Where where
(Where x) <> (Where y) = Where (x <> y)
deriving instance Semigroup Where
instance Monoid Top where
mempty = NoTop

View File

@ -20,7 +20,7 @@ import Hasura.Prelude
import Language.Haskell.TH
import Language.Haskell.TH.Syntax
$( fmap concat $ for
$( concat <$> for
[''Aliased]
\name ->
[d|
@ -42,7 +42,7 @@ $( fmap concat $ for
|]
)
$( fmap concat $ for
$( concat <$> for
[ ''Where,
''Aggregate,
''EntityAlias,
@ -81,7 +81,7 @@ $( fmap concat $ for
|]
)
$( fmap concat $ for
$( concat <$> for
[ ''ScalarType
]
\name ->
@ -98,17 +98,17 @@ $( fmap concat $ for
|]
)
$( fmap concat $ for
$( concat <$> for
[''TableName, ''ScalarType]
\name -> [d|deriving instance Ord $(conT name)|]
)
$( fmap concat $ for
$( concat <$> for
[''TableName, ''NullsOrder, ''Order]
\name -> [d|deriving instance Lift $(conT name)|]
)
$( fmap concat $ for
$( concat <$> for
[''Order, ''NullsOrder, ''ScalarType, ''FieldName]
\name ->
[d|
@ -167,11 +167,9 @@ instance ToJSONKey ScalarType
instance ToTxt ScalarType where
toTxt = tshow
instance Monoid Where where
mempty = Where mempty
deriving newtype instance Monoid Where
instance Semigroup Where where
(Where x) <> (Where y) = Where (x <> y)
deriving newtype instance Semigroup Where
instance Monoid Top where
mempty = NoTop

View File

@ -36,6 +36,7 @@ import Data.ByteString.Lazy qualified as LBS
import Data.Dependent.Map qualified as DM
import Data.Environment qualified as Env
import Data.HashMap.Strict.InsOrd qualified as OMap
import Data.Monoid (Any (..))
import Data.Text qualified as T
import Hasura.Backends.Postgres.Instances.Transport (runPGMutationTransaction)
import Hasura.Base.Error
@ -226,17 +227,11 @@ buildResponse telemType res f = case res of
-- | A predicate on session variables. The 'Monoid' instance makes it simple
-- to combine several predicates disjunctively.
newtype SessVarPred = SessVarPred {unSessVarPred :: SessionVariable -> SessionVariableValue -> Bool}
deriving (Semigroup, Monoid) via (SessionVariable -> SessionVariableValue -> Any)
keepAllSessionVariables :: SessVarPred
keepAllSessionVariables = SessVarPred $ \_ _ -> True
instance Semigroup SessVarPred where
SessVarPred p1 <> SessVarPred p2 = SessVarPred $ \sv svv ->
p1 sv svv || p2 sv svv
instance Monoid SessVarPred where
mempty = SessVarPred $ \_ _ -> False
runSessVarPred :: SessVarPred -> SessionVariables -> SessionVariables
runSessVarPred = filterSessionVariables . unSessVarPred