Document the Semigroup for Map
[packages/containers.git] / Utils / Containers / Internal / StrictMaybe.hs
1 {-# LANGUAGE CPP #-}
2
3 #include "containers.h"
4
5 {-# OPTIONS_HADDOCK hide #-}
6 -- | Strict 'Maybe'
7
8 module Utils.Containers.Internal.StrictMaybe (MaybeS (..), maybeS, toMaybe, toMaybeS) where
9
10 #if !MIN_VERSION_base(4,8,0)
11 import Data.Foldable (Foldable (..))
12 import Data.Monoid (Monoid (..))
13 #endif
14
15 data MaybeS a = NothingS | JustS !a
16
17 instance Foldable MaybeS where
18 foldMap _ NothingS = mempty
19 foldMap f (JustS a) = f a
20
21 maybeS :: r -> (a -> r) -> MaybeS a -> r
22 maybeS n _ NothingS = n
23 maybeS _ j (JustS a) = j a
24
25 toMaybe :: MaybeS a -> Maybe a
26 toMaybe NothingS = Nothing
27 toMaybe (JustS a) = Just a
28
29 toMaybeS :: Maybe a -> MaybeS a
30 toMaybeS Nothing = NothingS
31 toMaybeS (Just a) = JustS a