We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4faa2ec commit 716e1aaCopy full SHA for 716e1aa
src/Opaleye/Internal/MaybeFields.hs
@@ -92,6 +92,14 @@ justFields = pure
92
maybeFields :: PP.Default IfPP b b => b -> (a -> b) -> MaybeFields a -> b
93
maybeFields = maybeFieldsExplicit PP.def
94
95
+matchMaybe :: PP.Default IfPP b b => MaybeFields a -> (Maybe a -> b) -> b
96
+matchMaybe mf f = maybeFields (f Nothing) (f . Just) mf
97
+
98
+example :: (Num a, PP.Default IfPP a a) => MaybeFields a -> a
99
+example mf = matchMaybe mf $ \case
100
+ Nothing -> 0
101
+ Just x -> x * 100
102
103
-- | The Opaleye analogue of 'Data.Maybe.fromMaybe'
104
fromMaybeFields :: PP.Default IfPP b b => b -> MaybeFields b -> b
105
fromMaybeFields = fromMaybeFieldsExplicit PP.def
0 commit comments