Safe Haskell  Safe 

Language  Haskell2010 
Synopsis
 data Maybe a
 maybe :: b > (a > b) > Maybe a > b
 maybeM :: Monad m => m b > (a > m b) > m (Maybe a) > m b
 isJust :: Maybe a > Bool
 isNothing :: Maybe a > Bool
 fromMaybe :: a > Maybe a > a
 listToMaybe :: [a] > Maybe a
 maybeToList :: Maybe a > [a]
 catMaybes :: [Maybe a] > [a]
 mapMaybe :: (a > Maybe b) > [a] > [b]
 _Just :: (Choice p, Applicative f) => p a (f b) > p (Maybe a) (f (Maybe b))
 _Nothing :: (Choice p, Applicative f) => p () (f ()) > p (Maybe a) (f (Maybe a))
 newtype Option a = Option {}
 option :: b > (a > b) > Option a > b
 newtype First a = First {}
 newtype Last a = Last {}
Maybe
The Maybe
type encapsulates an optional value. A value of type
either contains a value of type Maybe
aa
(represented as
),
or it is empty (represented as Just
aNothing
). Using Maybe
is a good way to
deal with errors or exceptional cases without resorting to drastic
measures such as error
.
The Maybe
type is also a monad. It is a simple kind of error
monad, where all errors are represented by Nothing
. A richer
error monad can be built using the Either
type.
Instances
Monad Maybe  Since: base2.1 
Functor Maybe  Since: base2.1 
MonadFix Maybe  Since: base2.1 
Defined in Control.Monad.Fix  
MonadFail Maybe  Since: base4.9.0.0 
Defined in Control.Monad.Fail  
Applicative Maybe  Since: base2.1 
Foldable Maybe  Since: base2.1 
Defined in Data.Foldable 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 # elem :: Eq a => a > Maybe a > Bool # maximum :: Ord a => Maybe a > a # minimum :: Ord a => Maybe a > a #  
Traversable Maybe  Since: base2.1 
Alternative Maybe  Since: base2.1 
ToJSON1 Maybe  
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a > Value) > ([a] > Value) > Maybe a > Value # liftToJSONList :: (a > Value) > ([a] > Value) > [Maybe a] > Value # liftToEncoding :: (a > Encoding) > ([a] > Encoding) > Maybe a > Encoding # liftToEncodingList :: (a > Encoding) > ([a] > Encoding) > [Maybe a] > Encoding #  
FromJSON1 Maybe  
MonadPlus Maybe  Since: base2.1 
Eq1 Maybe  Since: base4.9.0.0 
Ord1 Maybe  Since: base4.9.0.0 
Defined in Data.Functor.Classes  
Read1 Maybe  Since: base4.9.0.0 
Defined in Data.Functor.Classes  
Show1 Maybe  Since: base4.9.0.0 
MonadZip Maybe  Since: base4.8.0.0 
Compactable Maybe  
Defined in Control.Compactable compact :: Maybe (Maybe a) > Maybe a # separate :: Maybe (Either l r) > (Maybe l, Maybe r) # filter :: (a > Bool) > Maybe a > Maybe a # partition :: (a > Bool) > Maybe a > (Maybe a, Maybe a) # fmapMaybe :: Functor Maybe => (a > Maybe b) > Maybe a > Maybe b # fmapEither :: Functor Maybe => (a > Either l r) > Maybe a > (Maybe l, Maybe r) # applyMaybe :: Applicative Maybe => Maybe (a > Maybe b) > Maybe a > Maybe b # applyEither :: Applicative Maybe => Maybe (a > Either l r) > Maybe a > (Maybe l, Maybe r) # bindMaybe :: Monad Maybe => Maybe a > (a > Maybe (Maybe b)) > Maybe b # bindEither :: Monad Maybe => Maybe a > (a > Maybe (Either l r)) > (Maybe l, Maybe r) # traverseMaybe :: (Applicative g, Traversable Maybe) => (a > g (Maybe b)) > Maybe a > g (Maybe b) # traverseEither :: (Applicative g, Traversable Maybe) => (a > g (Either l r)) > Maybe a > g (Maybe l, Maybe r) #  
CompactFold Maybe  
Defined in Control.Compactable compactFold :: Foldable g => Maybe (g a) > Maybe a # separateFold :: Bifoldable g => Maybe (g a b) > (Maybe a, Maybe b) # fmapFold :: (Functor Maybe, Foldable g) => (a > g b) > Maybe a > Maybe b # fmapBifold :: (Functor Maybe, Bifoldable g) => (a > g l r) > Maybe a > (Maybe l, Maybe r) # applyFold :: (Applicative Maybe, Foldable g) => Maybe (a > g b) > Maybe a > Maybe b # applyBifold :: (Applicative Maybe, Bifoldable g) => Maybe (a > g l r) > Maybe a > (Maybe l, Maybe r) # bindFold :: (Monad Maybe, Foldable g) => Maybe a > (a > Maybe (g b)) > Maybe b # bindBifold :: (Monad Maybe, Bifoldable g) => Maybe a > (a > Maybe (g l r)) > (Maybe l, Maybe r) # traverseFold :: (Applicative h, Foldable g, Traversable Maybe) => (a > h (g b)) > Maybe a > h (Maybe b) # traverseBifold :: (Applicative h, Bifoldable g, Traversable Maybe) => (a > h (g l r)) > Maybe a > h (Maybe l, Maybe r) #  
NFData1 Maybe  Since: deepseq1.4.3.0 
Defined in Control.DeepSeq  
MonadThrow Maybe  
Defined in Control.Monad.Catch  
Hashable1 Maybe  
Defined in Data.Hashable.Class  
Apply Maybe  
Pointed Maybe  
Defined in Data.Pointed  
Plus Maybe  
Defined in Data.Functor.Plus  
Alt Maybe  
Bind Maybe  
Extend Maybe  
MonadError () Maybe  Since: mtl2.2.2 
Defined in Control.Monad.Error.Class throwError :: () > Maybe a # catchError :: Maybe a > (() > Maybe a) > Maybe a #  
MonadBase Maybe Maybe  
Defined in Control.Monad.Base  
(Selector s, GToJSON enc arity (K1 i (Maybe a) :: * > *), KeyValuePair enc pairs, Monoid pairs) => RecordToPairs enc pairs arity (S1 s (K1 i (Maybe a) :: * > *))  
Defined in Data.Aeson.Types.ToJSON  
() :=> (Functor Maybe)  
() :=> (Applicative Maybe)  
Defined in Data.Constraint ins :: () : Applicative Maybe #  
() :=> (Alternative Maybe)  
Defined in Data.Constraint ins :: () : Alternative Maybe #  
() :=> (MonadPlus Maybe)  
(Selector s, FromJSON a) => FromRecord arity (S1 s (K1 i (Maybe a) :: * > *))  
Defined in Data.Aeson.Types.FromJSON  
Eq a => Eq (Maybe a)  
Data a => Data (Maybe a)  Since: base4.0.0.0 
Defined in Data.Data gfoldl :: (forall d b. Data d => c (d > b) > d > c b) > (forall g. g > c g) > Maybe a > c (Maybe a) # gunfold :: (forall b r. Data b => c (b > r) > c r) > (forall r. r > c r) > Constr > c (Maybe a) # toConstr :: Maybe a > Constr # dataTypeOf :: Maybe a > DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) > Maybe (c (Maybe a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) > Maybe (c (Maybe a)) # gmapT :: (forall b. Data b => b > b) > Maybe a > Maybe a # gmapQl :: (r > r' > r) > r > (forall d. Data d => d > r') > Maybe a > r # gmapQr :: (r' > r > r) > r > (forall d. Data d => d > r') > Maybe a > r # gmapQ :: (forall d. Data d => d > u) > Maybe a > [u] # gmapQi :: Int > (forall d. Data d => d > u) > Maybe a > u # gmapM :: Monad m => (forall d. Data d => d > m d) > Maybe a > m (Maybe a) # gmapMp :: MonadPlus m => (forall d. Data d => d > m d) > Maybe a > m (Maybe a) # gmapMo :: MonadPlus m => (forall d. Data d => d > m d) > Maybe a > m (Maybe a) #  
Ord a => Ord (Maybe a)  
Read a => Read (Maybe a)  Since: base2.1 
Show a => Show (Maybe a)  
Generic (Maybe a)  
Semigroup a => Semigroup (Maybe a)  Since: base4.9.0.0 
Semigroup a => Monoid (Maybe a)  Lift a semigroup into Since 4.11.0: constraint on inner Since: base2.1 
Lift a => Lift (Maybe a)  
Hashable a => Hashable (Maybe a)  
Defined in Data.Hashable.Class  
ToJSON a => ToJSON (Maybe a)  
Defined in Data.Aeson.Types.ToJSON  
FromJSON a => FromJSON (Maybe a)  
SingKind a => SingKind (Maybe a)  Since: base4.9.0.0 
NFData a => NFData (Maybe a)  
Defined in Control.DeepSeq  
Ixed (Maybe a)  
Defined in Control.Lens.At  
At (Maybe a)  
AsEmpty (Maybe a)  
Defined in Control.Lens.Empty  
Pretty a => Pretty (Maybe a)  Ignore

Defined in Data.Text.Prettyprint.Doc.Internal  
Lower (Maybe a)  
Defined in Data.Semilattice.Lower lowerBound :: Maybe a #  
Serialise a => Serialise (Maybe a)  Since: serialise0.2.0.0 
Generic1 Maybe  
SingI (Nothing :: Maybe a)  Since: base4.9.0.0 
Defined in GHC.Generics  
(Eq a) :=> (Eq (Maybe a))  
(Ord a) :=> (Ord (Maybe a))  
(Read a) :=> (Read (Maybe a))  
(Show a) :=> (Show (Maybe a))  
(Semigroup a) :=> (Semigroup (Maybe a))  
(Monoid a) :=> (Monoid (Maybe a))  
Each (Maybe a) (Maybe b) a b 

SingI a2 => SingI (Just a2 :: Maybe a1)  Since: base4.9.0.0 
Defined in GHC.Generics  
(Selector c, ToJSON a) => GtoJson (M1 S c (K1 i (Maybe a) :: * > *))  
(Selector c, FromJSON a) => GfromJson (M1 S c (K1 i (Maybe a) :: * > *))  
type Rep (Maybe a)  
data Sing (b :: Maybe a)  
type DemoteRep (Maybe a)  
Defined in GHC.Generics  
type Index (Maybe a)  
Defined in Control.Lens.At  
type IxValue (Maybe a)  
Defined in Control.Lens.At  
type Rep1 Maybe  
maybe :: b > (a > b) > Maybe a > b #
The maybe
function takes a default value, a function, and a Maybe
value. If the Maybe
value is Nothing
, the function returns the
default value. Otherwise, it applies the function to the value inside
the Just
and returns the result.
Examples
Basic usage:
>>>
maybe False odd (Just 3)
True
>>>
maybe False odd Nothing
False
Read an integer from a string using readMaybe
. If we succeed,
return twice the integer; that is, apply (*2)
to it. If instead
we fail to parse an integer, return 0
by default:
>>>
import Text.Read ( readMaybe )
>>>
maybe 0 (*2) (readMaybe "5")
10>>>
maybe 0 (*2) (readMaybe "")
0
Apply show
to a Maybe Int
. If we have Just n
, we want to show
the underlying Int
n
. But if we have Nothing
, we return the
empty string instead of (for example) "Nothing":
>>>
maybe "" show (Just 5)
"5">>>
maybe "" show Nothing
""
fromMaybe :: a > Maybe a > a #
The fromMaybe
function takes a default value and and Maybe
value. If the Maybe
is Nothing
, it returns the default values;
otherwise, it returns the value contained in the Maybe
.
Examples
Basic usage:
>>>
fromMaybe "" (Just "Hello, World!")
"Hello, World!"
>>>
fromMaybe "" Nothing
""
Read an integer from a string using readMaybe
. If we fail to
parse an integer, we want to return 0
by default:
>>>
import Text.Read ( readMaybe )
>>>
fromMaybe 0 (readMaybe "5")
5>>>
fromMaybe 0 (readMaybe "")
0
listToMaybe :: [a] > Maybe a #
The listToMaybe
function returns Nothing
on an empty list
or
where Just
aa
is the first element of the list.
Examples
Basic usage:
>>>
listToMaybe []
Nothing
>>>
listToMaybe [9]
Just 9
>>>
listToMaybe [1,2,3]
Just 1
Composing maybeToList
with listToMaybe
should be the identity
on singleton/empty lists:
>>>
maybeToList $ listToMaybe [5]
[5]>>>
maybeToList $ listToMaybe []
[]
But not on lists with more than one element:
>>>
maybeToList $ listToMaybe [1,2,3]
[1]
maybeToList :: Maybe a > [a] #
The maybeToList
function returns an empty list when given
Nothing
or a singleton list when not given Nothing
.
Examples
Basic usage:
>>>
maybeToList (Just 7)
[7]
>>>
maybeToList Nothing
[]
One can use maybeToList
to avoid pattern matching when combined
with a function that (safely) works on lists:
>>>
import Text.Read ( readMaybe )
>>>
sum $ maybeToList (readMaybe "3")
3>>>
sum $ maybeToList (readMaybe "")
0
catMaybes :: [Maybe a] > [a] #
The catMaybes
function takes a list of Maybe
s and returns
a list of all the Just
values.
Examples
Basic usage:
>>>
catMaybes [Just 1, Nothing, Just 3]
[1,3]
When constructing a list of Maybe
values, catMaybes
can be used
to return all of the "success" results (if the list is the result
of a map
, then mapMaybe
would be more appropriate):
>>>
import Text.Read ( readMaybe )
>>>
[readMaybe x :: Maybe Int  x < ["1", "Foo", "3"] ]
[Just 1,Nothing,Just 3]>>>
catMaybes $ [readMaybe x :: Maybe Int  x < ["1", "Foo", "3"] ]
[1,3]
mapMaybe :: (a > Maybe b) > [a] > [b] #
The mapMaybe
function is a version of map
which can throw
out elements. In particular, the functional argument returns
something of type
. If this is Maybe
bNothing
, no element
is added on to the result list. If it is
, then Just
bb
is
included in the result list.
Examples
Using
is a shortcut for mapMaybe
f x
in most cases:catMaybes
$ map
f x
>>>
import Text.Read ( readMaybe )
>>>
let readMaybeInt = readMaybe :: String > Maybe Int
>>>
mapMaybe readMaybeInt ["1", "Foo", "3"]
[1,3]>>>
catMaybes $ map readMaybeInt ["1", "Foo", "3"]
[1,3]
If we map the Just
constructor, the entire list should be returned:
>>>
mapMaybe Just [1,2,3]
[1,2,3]
Prisms
_Just :: (Choice p, Applicative f) => p a (f b) > p (Maybe a) (f (Maybe b)) #
This Prism
provides a Traversal
for tweaking the target of the value of Just
in a Maybe
.
>>>
over _Just (+1) (Just 2)
Just 3
Unlike traverse
this is a Prism
, and so you can use it to inject as well:
>>>
_Just # 5
Just 5
>>>
5^.re _Just
Just 5
Interestingly,
m^?
_Just
≡ m
>>>
Just x ^? _Just
Just x
>>>
Nothing ^? _Just
Nothing
Newtypes
Option
is effectively Maybe
with a better instance of
Monoid
, built off of an underlying Semigroup
instead of an
underlying Monoid
.
Ideally, this type would not exist at all and we would just fix the
Monoid
instance of Maybe
Instances
Monad Option  Since: base4.9.0.0 
Functor Option  Since: base4.9.0.0 
MonadFix Option  Since: base4.9.0.0 
Defined in Data.Semigroup  
Applicative Option  Since: base4.9.0.0 
Foldable Option  Since: base4.9.0.0 
Defined in Data.Semigroup fold :: Monoid m => Option m > m # foldMap :: Monoid m => (a > m) > Option a > m # foldr :: (a > b > b) > b > Option a > b # foldr' :: (a > b > b) > b > Option a > b # foldl :: (b > a > b) > b > Option a > b # foldl' :: (b > a > b) > b > Option a > b # foldr1 :: (a > a > a) > Option a > a # foldl1 :: (a > a > a) > Option a > a # elem :: Eq a => a > Option a > Bool # maximum :: Ord a => Option a > a # minimum :: Ord a => Option a > a #  
Traversable Option  Since: base4.9.0.0 
Alternative Option  Since: base4.9.0.0 
ToJSON1 Option  
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a > Value) > ([a] > Value) > Option a > Value # liftToJSONList :: (a > Value) > ([a] > Value) > [Option a] > Value # liftToEncoding :: (a > Encoding) > ([a] > Encoding) > Option a > Encoding # liftToEncodingList :: (a > Encoding) > ([a] > Encoding) > [Option a] > Encoding #  
FromJSON1 Option  
MonadPlus Option  Since: base4.9.0.0 
Compactable Option  
Defined in Control.Compactable compact :: Option (Maybe a) > Option a # separate :: Option (Either l r) > (Option l, Option r) # filter :: (a > Bool) > Option a > Option a # partition :: (a > Bool) > Option a > (Option a, Option a) # fmapMaybe :: Functor Option => (a > Maybe b) > Option a > Option b # fmapEither :: Functor Option => (a > Either l r) > Option a > (Option l, Option r) # applyMaybe :: Applicative Option => Option (a > Maybe b) > Option a > Option b # applyEither :: Applicative Option => Option (a > Either l r) > Option a > (Option l, Option r) # bindMaybe :: Monad Option => Option a > (a > Option (Maybe b)) > Option b # bindEither :: Monad Option => Option a > (a > Option (Either l r)) > (Option l, Option r) # traverseMaybe :: (Applicative g, Traversable Option) => (a > g (Maybe b)) > Option a > g (Option b) # traverseEither :: (Applicative g, Traversable Option) => (a > g (Either l r)) > Option a > g (Option l, Option r) #  
CompactFold Option  
Defined in Control.Compactable compactFold :: Foldable g => Option (g a) > Option a # separateFold :: Bifoldable g => Option (g a b) > (Option a, Option b) # fmapFold :: (Functor Option, Foldable g) => (a > g b) > Option a > Option b # fmapBifold :: (Functor Option, Bifoldable g) => (a > g l r) > Option a > (Option l, Option r) # applyFold :: (Applicative Option, Foldable g) => Option (a > g b) > Option a > Option b # applyBifold :: (Applicative Option, Bifoldable g) => Option (a > g l r) > Option a > (Option l, Option r) # bindFold :: (Monad Option, Foldable g) => Option a > (a > Option (g b)) > Option b # bindBifold :: (Monad Option, Bifoldable g) => Option a > (a > Option (g l r)) > (Option l, Option r) # traverseFold :: (Applicative h, Foldable g, Traversable Option) => (a > h (g b)) > Option a > h (Option b) # traverseBifold :: (Applicative h, Bifoldable g, Traversable Option) => (a > h (g l r)) > Option a > h (Option l, Option r) #  
NFData1 Option  Since: deepseq1.4.3.0 
Defined in Control.DeepSeq  
Apply Option  
Pointed Option  
Defined in Data.Pointed  
Plus Option  
Defined in Data.Functor.Plus  
Alt Option  
Bind Option  
(Selector s, GToJSON enc arity (K1 i (Maybe a) :: * > *), KeyValuePair enc pairs, Monoid pairs) => RecordToPairs enc pairs arity (S1 s (K1 i (Option a) :: * > *))  
Defined in Data.Aeson.Types.ToJSON  
(Selector s, FromJSON a) => FromRecord arity (S1 s (K1 i (Option a) :: * > *))  
Defined in Data.Aeson.Types.FromJSON  
Eq a => Eq (Option a)  
Data a => Data (Option a)  
Defined in Data.Semigroup gfoldl :: (forall d b. Data d => c (d > b) > d > c b) > (forall g. g > c g) > Option a > c (Option a) # gunfold :: (forall b r. Data b => c (b > r) > c r) > (forall r. r > c r) > Constr > c (Option a) # toConstr :: Option a > Constr # dataTypeOf :: Option a > DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) > Maybe (c (Option a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) > Maybe (c (Option a)) # gmapT :: (forall b. Data b => b > b) > Option a > Option a # gmapQl :: (r > r' > r) > r > (forall d. Data d => d > r') > Option a > r # gmapQr :: (r' > r > r) > r > (forall d. Data d => d > r') > Option a > r # gmapQ :: (forall d. Data d => d > u) > Option a > [u] # gmapQi :: Int > (forall d. Data d => d > u) > Option a > u # gmapM :: Monad m => (forall d. Data d => d > m d) > Option a > m (Option a) # gmapMp :: MonadPlus m => (forall d. Data d => d > m d) > Option a > m (Option a) # gmapMo :: MonadPlus m => (forall d. Data d => d > m d) > Option a > m (Option a) #  
Ord a => Ord (Option a)  
Defined in Data.Semigroup  
Read a => Read (Option a)  
Show a => Show (Option a)  
Generic (Option a)  
Semigroup a => Semigroup (Option a)  Since: base4.9.0.0 
Semigroup a => Monoid (Option a)  Since: base4.9.0.0 
Hashable a => Hashable (Option a)  
Defined in Data.Hashable.Class  
ToJSON a => ToJSON (Option a)  
Defined in Data.Aeson.Types.ToJSON  
FromJSON a => FromJSON (Option a)  
NFData a => NFData (Option a)  Since: deepseq1.4.2.0 
Defined in Control.DeepSeq  
Wrapped (Option a)  
Serialise a => Serialise (Option a)  Since: serialise0.2.0.0 
Generic1 Option  
t ~ Option b => Rewrapped (Option a) t  
Defined in Control.Lens.Wrapped  
type Rep (Option a)  
Defined in Data.Semigroup  
type Unwrapped (Option a)  
Defined in Control.Lens.Wrapped  
type Rep1 Option  
Defined in Data.Semigroup 
Maybe monoid returning the leftmost nonNothing value.
is isomorphic to First
a
, but precedes it
historically.Alt
Maybe
a
>>>
getFirst (First (Just "hello") <> First Nothing <> First (Just "world"))
Just "hello"
Instances
Monad First  
Functor First  
MonadFix First  Since: base4.8.0.0 
Defined in Control.Monad.Fix  
Applicative First  
Foldable First  Since: base4.8.0.0 
Defined in Data.Foldable fold :: Monoid m => First m > m # foldMap :: Monoid m => (a > m) > First a > m # foldr :: (a > b > b) > b > First a > b # foldr' :: (a > b > b) > b > First a > b # foldl :: (b > a > b) > b > First a > b # foldl' :: (b > a > b) > b > First a > b # foldr1 :: (a > a > a) > First a > a # foldl1 :: (a > a > a) > First a > a # elem :: Eq a => a > First a > Bool # maximum :: Ord a => First a > a # minimum :: Ord a => First a > a #  
Traversable First  Since: base4.8.0.0 
ToJSON1 First  
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a > Value) > ([a] > Value) > First a > Value # liftToJSONList :: (a > Value) > ([a] > Value) > [First a] > Value # liftToEncoding :: (a > Encoding) > ([a] > Encoding) > First a > Encoding # liftToEncodingList :: (a > Encoding) > ([a] > Encoding) > [First a] > Encoding #  
FromJSON1 First  
MonadZip First  Since: base4.8.0.0 
NFData1 First  Since: deepseq1.4.3.0 
Defined in Control.DeepSeq  
Apply First  
Pointed First  
Defined in Data.Pointed  
Plus First  
Defined in Data.Functor.Plus  
Alt First  
Bind First  
Eq a => Eq (First a)  
Data a => Data (First a)  Since: base4.8.0.0 
Defined in Data.Data gfoldl :: (forall d b. Data d => c (d > b) > d > c b) > (forall g. g > c g) > First a > c (First a) # gunfold :: (forall b r. Data b => c (b > r) > c r) > (forall r. r > c r) > Constr > c (First a) # toConstr :: First a > Constr # dataTypeOf :: First a > DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) > Maybe (c (First a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) > Maybe (c (First a)) # gmapT :: (forall b. Data b => b > b) > First a > First a # gmapQl :: (r > r' > r) > r > (forall d. Data d => d > r') > First a > r # gmapQr :: (r' > r > r) > r > (forall d. Data d => d > r') > First a > r # gmapQ :: (forall d. Data d => d > u) > First a > [u] # gmapQi :: Int > (forall d. Data d => d > u) > First a > u # gmapM :: Monad m => (forall d. Data d => d > m d) > First a > m (First a) # gmapMp :: MonadPlus m => (forall d. Data d => d > m d) > First a > m (First a) # gmapMo :: MonadPlus m => (forall d. Data d => d > m d) > First a > m (First a) #  
Ord a => Ord (First a)  
Read a => Read (First a)  
Show a => Show (First a)  
Generic (First a)  
Semigroup (First a)  Since: base4.9.0.0 
Monoid (First a)  Since: base2.1 
ToJSON a => ToJSON (First a)  
Defined in Data.Aeson.Types.ToJSON  
FromJSON a => FromJSON (First a)  
NFData a => NFData (First a)  Since: deepseq1.4.0.0 
Defined in Control.DeepSeq  
Wrapped (First a)  
AsEmpty (First a)  
Defined in Control.Lens.Empty  
Lower (First a)  
Defined in Data.Semilattice.Lower lowerBound :: First a #  
Serialise a => Serialise (First a)  Since: serialise0.2.0.0 
Generic1 First  
t ~ First b => Rewrapped (First a) t  
Defined in Control.Lens.Wrapped  
type Rep (First a)  
Defined in Data.Monoid  
type Unwrapped (First a)  
Defined in Control.Lens.Wrapped  
type Rep1 First  
Defined in Data.Monoid 
Maybe monoid returning the rightmost nonNothing value.
is isomorphic to Last
a
, and thus to
Dual
(First
a)Dual
(Alt
Maybe
a)
>>>
getLast (Last (Just "hello") <> Last Nothing <> Last (Just "world"))
Just "world"
Instances
Monad Last  
Functor Last  
MonadFix Last  Since: base4.8.0.0 
Defined in Control.Monad.Fix  
Applicative Last  
Foldable Last  Since: base4.8.0.0 
Defined in Data.Foldable fold :: Monoid m => Last m > m # foldMap :: Monoid m => (a > m) > Last a > m # foldr :: (a > b > b) > b > Last a > b # foldr' :: (a > b > b) > b > Last a > b # foldl :: (b > a > b) > b > Last a > b # foldl' :: (b > a > b) > b > Last a > b # foldr1 :: (a > a > a) > Last a > a # foldl1 :: (a > a > a) > Last a > a # elem :: Eq a => a > Last a > Bool # maximum :: Ord a => Last a > a #  
Traversable Last  Since: base4.8.0.0 
ToJSON1 Last  
Defined in Data.Aeson.Types.ToJSON  
FromJSON1 Last  
MonadZip Last  Since: base4.8.0.0 
NFData1 Last  Since: deepseq1.4.3.0 
Defined in Control.DeepSeq  
Apply Last  
Pointed Last  
Defined in Data.Pointed  
Plus Last  
Defined in Data.Functor.Plus  
Alt Last  
Bind Last  
Eq a => Eq (Last a)  
Data a => Data (Last a)  Since: base4.8.0.0 
Defined in Data.Data gfoldl :: (forall d b. Data d => c (d > b) > d > c b) > (forall g. g > c g) > Last a > c (Last a) # gunfold :: (forall b r. Data b => c (b > r) > c r) > (forall r. r > c r) > Constr > c (Last a) # toConstr :: Last a > Constr # dataTypeOf :: Last a > DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) > Maybe (c (Last a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) > Maybe (c (Last a)) # gmapT :: (forall b. Data b => b > b) > Last a > Last a # gmapQl :: (r > r' > r) > r > (forall d. Data d => d > r') > Last a > r # gmapQr :: (r' > r > r) > r > (forall d. Data d => d > r') > Last a > r # gmapQ :: (forall d. Data d => d > u) > Last a > [u] # gmapQi :: Int > (forall d. Data d => d > u) > Last a > u # gmapM :: Monad m => (forall d. Data d => d > m d) > Last a > m (Last a) # gmapMp :: MonadPlus m => (forall d. Data d => d > m d) > Last a > m (Last a) # gmapMo :: MonadPlus m => (forall d. Data d => d > m d) > Last a > m (Last a) #  
Ord a => Ord (Last a)  
Read a => Read (Last a)  
Show a => Show (Last a)  
Generic (Last a)  
Semigroup (Last a)  Since: base4.9.0.0 
Monoid (Last a)  Since: base2.1 
ToJSON a => ToJSON (Last a)  
Defined in Data.Aeson.Types.ToJSON  
FromJSON a => FromJSON (Last a)  
NFData a => NFData (Last a)  Since: deepseq1.4.0.0 
Defined in Control.DeepSeq  
Wrapped (Last a)  
AsEmpty (Last a)  
Defined in Control.Lens.Empty  
Lower (Last a)  
Defined in Data.Semilattice.Lower lowerBound :: Last a #  
Serialise a => Serialise (Last a)  Since: serialise0.2.0.0 
Generic1 Last  
t ~ Last b => Rewrapped (Last a) t  
Defined in Control.Lens.Wrapped  
type Rep (Last a)  
Defined in Data.Monoid  
type Unwrapped (Last a)  
Defined in Control.Lens.Wrapped  
type Rep1 Last  
Defined in Data.Monoid 