Skip to content

Commit

Permalink
WIP matchMaybe
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom authored and Tom committed Sep 5, 2021
1 parent 4faa2ec commit f03b182
Showing 1 changed file with 8 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 @@ -92,6 +92,14 @@ justFields = pure
maybeFields :: PP.Default IfPP b b => b -> (a -> b) -> MaybeFields a -> b
maybeFields = maybeFieldsExplicit PP.def

matchMaybe :: PP.Default IfPP b b => MaybeFields a -> (Maybe a -> b) -> b
matchMaybe mf f = maybeFields (f Nothing) (f . Just) mf

example :: MaybeFields a -> a
example mf = matchMaybe mf $ \case
Nothing -> 0
Just x -> x * 100

-- | The Opaleye analogue of 'Data.Maybe.fromMaybe'
fromMaybeFields :: PP.Default IfPP b b => b -> MaybeFields b -> b
fromMaybeFields = fromMaybeFieldsExplicit PP.def
Expand Down

0 comments on commit f03b182

Please sign in to comment.