tvl-depot/users/Profpatsch/whatcd-resolver/src/Optional.hs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

19 lines
464 B
Haskell
Raw Normal View History

module Optional where
import GHC.Records (getField)
import MyPrelude
newtype Optional a = OptionalInternal (Maybe a)
deriving newtype (Functor)
mkOptional :: a -> Optional a
mkOptional defaultValue = OptionalInternal $ Just defaultValue
defaults :: Optional a
defaults = OptionalInternal Nothing
instance HasField "withDefault" (Optional a) (a -> a) where
getField (OptionalInternal m) defaultValue = case m of
Nothing -> defaultValue
Just a -> a