{-# LANGUAGE CPP #-}

#include "containers.h"

{-# OPTIONS_HADDOCK hide #-}
-- | Strict 'Maybe'

module Utils.Containers.Internal.StrictMaybe (MaybeS (..), maybeS, toMaybe, toMaybeS) where

data MaybeS a = NothingS | JustS !a

instance Foldable MaybeS where
  foldMap :: (a -> m) -> MaybeS a -> m
foldMap a -> m
_ MaybeS a
NothingS = m
forall a. Monoid a => a
mempty
  foldMap a -> m
f (JustS a
a) = a -> m
f a
a

maybeS :: r -> (a -> r) -> MaybeS a -> r
maybeS :: r -> (a -> r) -> MaybeS a -> r
maybeS r
n a -> r
_ MaybeS a
NothingS = r
n
maybeS r
_ a -> r
j (JustS a
a) = a -> r
j a
a

toMaybe :: MaybeS a -> Maybe a
toMaybe :: MaybeS a -> Maybe a
toMaybe MaybeS a
NothingS = Maybe a
forall a. Maybe a
Nothing
toMaybe (JustS a
a) = a -> Maybe a
forall a. a -> Maybe a
Just a
a

toMaybeS :: Maybe a -> MaybeS a
toMaybeS :: Maybe a -> MaybeS a
toMaybeS Maybe a
Nothing = MaybeS a
forall a. MaybeS a
NothingS
toMaybeS (Just a
a) = a -> MaybeS a
forall a. a -> MaybeS a
JustS a
a