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