Safe HaskellSafe

Eta.Types.Maybe

Description

The Maybe type encapsulates an optional value.

It either contains a value, represented by Just a, or not, represented by Nothing.

Synopsis

Documentation

data Maybe a :: * -> * #

Constructors

Nothing 
Just a 

Instances

Monad Maybe 

Methods

(>>=) :: Maybe a -> (a -> Maybe b) -> Maybe b #

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

return :: a -> Maybe a

fail :: String -> Maybe a

Functor Maybe 

Methods

fmap :: (a -> b) -> Maybe a -> Maybe b #

(<$) :: a -> Maybe b -> Maybe a

Applicative Maybe 

Methods

pure :: a -> Maybe a #

(<*>) :: Maybe (a -> b) -> Maybe a -> Maybe b #

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

(<*) :: Maybe a -> Maybe b -> Maybe a

Foldable Maybe 

Methods

fold :: Monoid m => Maybe m -> m

foldMap :: Monoid m => (a -> m) -> Maybe a -> m #

foldr :: (a -> b -> b) -> b -> Maybe a -> b #

foldr' :: (a -> b -> b) -> b -> Maybe a -> b

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

foldl' :: (b -> a -> b) -> b -> Maybe a -> b

foldr1 :: (a -> a -> a) -> Maybe a -> a

foldl1 :: (a -> a -> a) -> Maybe a -> a

toList :: Maybe a -> [a]

null :: Maybe a -> Bool

length :: Maybe a -> Int

elem :: Eq a => a -> Maybe a -> Bool

maximum :: Ord a => Maybe a -> a

minimum :: Ord a => Maybe a -> a

sum :: Num a => Maybe a -> a

product :: Num a => Maybe a -> a

Traversable Maybe 

Methods

traverse :: Applicative f => (a -> f b) -> Maybe a -> f (Maybe b) #

sequenceA :: Applicative f => Maybe (f a) -> f (Maybe a) #

mapM :: Monad m => (a -> m b) -> Maybe a -> m (Maybe b)

sequence :: Monad m => Maybe (m a) -> m (Maybe a)

Generic1 Maybe 

Associated Types

type Rep1 (Maybe :: * -> *) :: * -> *

Methods

from1 :: Maybe a -> Rep1 Maybe a

to1 :: Rep1 Maybe a -> Maybe a

MonadPlus Maybe 

Methods

mzero :: Maybe a

mplus :: Maybe a -> Maybe a -> Maybe a

Alternative Maybe 

Methods

empty :: Maybe a #

(<|>) :: Maybe a -> Maybe a -> Maybe a #

some :: Maybe a -> Maybe [a] #

many :: Maybe a -> Maybe [a] #

Eq a => Eq (Maybe a) 

Methods

(==) :: Maybe a -> Maybe a -> Bool #

(/=) :: Maybe a -> Maybe a -> Bool #

Ord a => Ord (Maybe a) 

Methods

compare :: Maybe a -> Maybe a -> Ordering #

(<) :: Maybe a -> Maybe a -> Bool #

(<=) :: Maybe a -> Maybe a -> Bool #

(>) :: Maybe a -> Maybe a -> Bool #

(>=) :: Maybe a -> Maybe a -> Bool #

max :: Maybe a -> Maybe a -> Maybe a #

min :: Maybe a -> Maybe a -> Maybe a #

Read a => Read (Maybe a) 

Methods

readsPrec :: Int -> ReadS (Maybe a) #

readList :: ReadS [Maybe a]

readPrec :: ReadPrec (Maybe a)

readListPrec :: ReadPrec [Maybe a]

Show a => Show (Maybe a) 

Methods

showsPrec :: Int -> Maybe a -> ShowS #

show :: Maybe a -> String #

showList :: [Maybe a] -> ShowS #

Generic (Maybe a) 

Associated Types

type Rep (Maybe a) :: * -> *

Methods

from :: Maybe a -> Rep (Maybe a) x

to :: Rep (Maybe a) x -> Maybe a

Monoid a => Monoid (Maybe a) 

Methods

mempty :: Maybe a #

mappend :: Maybe a -> Maybe a -> Maybe a #

mconcat :: [Maybe a] -> Maybe a #

SingKind a (KProxy a) => SingKind (Maybe a) (KProxy (Maybe a)) 

Associated Types

type DemoteRep (KProxy (Maybe a)) (kparam :: KProxy (KProxy (Maybe a))) :: *

Methods

fromSing :: Sing (KProxy (Maybe a)) a -> DemoteRep (KProxy (Maybe a)) kparam

SingI (Maybe a) (Nothing a) 

Methods

sing :: Sing (Nothing a) a

SingI a a1 => SingI (Maybe a) (Just a a1) 

Methods

sing :: Sing (Just a a1) a

type Rep1 Maybe 
type Rep1 Maybe = D1 (MetaData "Maybe" "GHC.Base" "base" False) ((:+:) (C1 (MetaCons "Nothing" PrefixI False) U1) (C1 (MetaCons "Just" PrefixI False) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) Par1)))
type Rep (Maybe a) 
type Rep (Maybe a) = D1 (MetaData "Maybe" "GHC.Base" "base" False) ((:+:) (C1 (MetaCons "Nothing" PrefixI False) U1) (C1 (MetaCons "Just" PrefixI False) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a))))
data Sing (Maybe a) 
data Sing (Maybe a) where
type (==) (Maybe k) a b 
type (==) (Maybe k) a b = EqMaybe k a b
type DemoteRep (Maybe a) (KProxy (Maybe a)) 
type DemoteRep (Maybe a) (KProxy (Maybe a)) = Maybe (DemoteRep a (KProxy a))

isJust :: Maybe a -> Bool #

Returns True if the Maybe is a Just

Returns True if the Maybe is a Nothing

>>> import Eta.Classes.Show
>>> import Eta.Classes.Monoid

unsafeGetValue :: Maybe a -> a #

Warning: Partial functions should be avoided.

Extracts the element out of a Just. Throws an error if it is Nothing

>>> unsafeGetValue (Just 1)
1

getOrElse :: Maybe a -> a -> a #

Takes a default value and a Maybe value. If the Maybe is Nothing, it returns the default value, returns the contents of the Maybe

>>> x = Just "Something"
>>> x `getOrElse` "Nothing found!"
"Something"
>>> y = Nothing
>>> y `getOrElse` "Nothing found!"
"Nothing found!"

handleMaybe :: b -> (a -> b) -> Maybe a -> b #

Handler for the Maybe type Takes a default value, a function and a Maybe value. If the Maybe is Nothing, it returns the default value, otherwise, it maps the function and returns the result

>>> myMaybe = Just 42
>>> handleMaybe "Nothing found" (\x -> "Got: " <+> show x) myMaybe
"Got: 42"
>>> myMaybe' = Nothing
>>> handleMaybe "Nothing found" (\x -> "Got: " <+> show x) myMaybe'
"Nothing found"

onlyJustValues :: [Maybe a] -> [a] #

Discards all Nothings from the list, returning all values

>>> onlyJustValues [Just 1, Nothing, Just 2]
[1,2]