Files
loop/src/MaybeHelp.hs
T

45 lines
1.0 KiB
Haskell

{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TemplateHaskell #-}
module MaybeHelp where
import Control.Lens
import Data.Aeson
import Data.Aeson.TH
data Maybe' a = Just' {__Just' :: a} | Nothing'
--deriving (Eq, Ord, Show, Read, Generic) --Generic, Flat)
deriving (Eq, Ord, Show, Read) --Generic, Flat)
--instance ToJSON a => ToJSON (Maybe' a) where
-- toEncoding = genericToEncoding defaultOptions
--
--instance FromJSON a => FromJSON (Maybe' a)
--maybe' :: b -> (a -> b) -> Maybe' a -> b
fromJust' :: Maybe' a -> a
fromJust' mx = case mx of
Just' x -> x
Nothing' -> error "no fromJust'"
isJust' :: Maybe' a -> Bool
isJust' Just'{} = True
isJust' Nothing' = False
isNothing' :: Maybe' a -> Bool
isNothing' Just'{} = False
isNothing' Nothing' = True
strictify :: Maybe a -> Maybe' a
strictify Nothing = Nothing'
strictify (Just x) = Just' x
toggleJust :: Maybe a -> Maybe ()
toggleJust Nothing = Just ()
toggleJust _ = Nothing
makeLenses ''Maybe'
deriveJSON defaultOptions ''Maybe'