Skip to content

Commit

Permalink
Add isJustAnd
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjaguarpaw committed Oct 20, 2023
1 parent 8f051d7 commit c01ec60
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Opaleye/Internal/MaybeFields.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ traverseMaybeFields query = proc mfInput -> do

where a `implies` b = Opaleye.Internal.Operators.not a .|| b

isJustAnd ::
MaybeFields a ->
(a -> Opaleye.Field.Field SqlBool) ->
Opaleye.Field.Field SqlBool
isJustAnd ma cond = matchMaybe ma $ \case
Nothing -> Opaleye.SqlTypes.sqlBool False
Just a -> cond a

optional :: SelectArr i a -> SelectArr i (MaybeFields a)
optional = Opaleye.Internal.Lateral.laterally (optionalInternal (MaybeFields . isNotNull))
where isNotNull = Opaleye.Internal.Operators.not . Opaleye.Field.isNull
Expand Down
1 change: 1 addition & 0 deletions src/Opaleye/MaybeFields.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module Opaleye.MaybeFields (
fromMaybeFields,
maybeFields,
maybeFieldsToNullable,
isJustAnd,
-- * Creating a 'Select' which returns 'MaybeFields'
Opaleye.Join.optional,
Opaleye.MaybeFields.traverseMaybeFields,
Expand Down

0 comments on commit c01ec60

Please sign in to comment.