diff --git a/src/Opaleye/Internal/MaybeFields.hs b/src/Opaleye/Internal/MaybeFields.hs index 8d2a2abfa..2d863ec7c 100644 --- a/src/Opaleye/Internal/MaybeFields.hs +++ b/src/Opaleye/Internal/MaybeFields.hs @@ -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