strict-base-types-0.2.1: Strict variants of the types provided in base.

PortabilityGHC
Stabilityexperimental
MaintainerSimon Meier <iridcode@gmail.com>
Safe HaskellNone

Data.Maybe.Strict

Description

The strict variant of the standard Haskell Maybe type and the corresponding variants of the functions from Data.Maybe.

Note that in contrast to the standard lazy Maybe type, the strict Maybe type is not an applicative functor, and therefore also not a monad. The problem is the homomorphism law, which states that

pure f <*> pure x = pure (f x)  -- must hold for all f

This law does not hold for the expected applicative functor instance of Maybe, as this instance does not satisfy pure f <*> pure _|_ = pure (f _|_) for f = const.

Synopsis

Documentation

data Maybe a

The type of strict optional values.

Constructors

Nothing 
Just !a 

Instances

Functor Maybe 
Typeable1 Maybe 
Eq a => Eq (Maybe a) 
Data a => Data (Maybe a) 
Ord a => Ord (Maybe a) 
Read a => Read (Maybe a) 
Show a => Show (Maybe a) 
Generic (Maybe a) 
Arbitrary a => Arbitrary (Maybe a) 
ToJSON a => ToJSON (Maybe a) 
FromJSON a => FromJSON (Maybe a) 
Monoid a => Monoid (Maybe a) 
Binary a => Binary (Maybe a) 
NFData a => NFData (Maybe a) 
Strict (Maybe a) (Maybe a) 

maybe :: b -> (a -> b) -> Maybe a -> b

Given a default value, a function and a Maybe value, yields the default value if the Maybe value is Nothing and applies the function to the value stored in the Just otherwise.

isJust :: Maybe a -> Bool

Yields True iff the argument is of the form Just _.

isNothing :: Maybe a -> Bool

Yields True iff the argument is Nothing.

fromJust :: Maybe a -> a

Extracts the element out of a Just and throws an error if the argument is Nothing.

fromMaybe :: a -> Maybe a -> a

Given a default value and a Maybe, yield the default value if the Maybe argument is Nothing and extract the value out of the Just otherwise.

listToMaybe :: [a] -> Maybe aSource

Analogous to listToMaybe in Data.Maybe.

maybeToList :: Maybe a -> [a]Source

Analogous to maybeToList in Data.Maybe.

catMaybes :: [Maybe a] -> [a]Source

Analogous to catMaybes in Data.Maybe.

mapMaybe :: (a -> Maybe b) -> [a] -> [b]Source

Analogous to mapMaybe in Data.Maybe.

_Just :: Prism (Maybe a) (Maybe b) a bSource

Analogous to _Just in Control.Lens.Prism