:: Maybe a -> a -package:base
Extracts the element out of a
Just and throws an error if the
argument is
Nothing.
The
fromJust function extracts the element out of a
Just
and throws an error if its argument is
Nothing.
Examples
Basic usage:
>>> fromJust (Just 1)
1
>>> 2 * (fromJust (Just 10))
20
>>> 2 * (fromJust Nothing)
*** Exception: Maybe.fromJust: Nothing
...
WARNING: This function is partial. You can use case-matching instead.
The
fromJust function extracts the element out of a
Just
and throws an error if its argument is
Nothing.
Examples
Basic usage:
>>> fromJust (Just 1)
1
>>> 2 * (fromJust (Just 10))
20
>>> 2 * (fromJust Nothing)
*** Exception: Maybe.fromJust: Nothing
The
fromJust function extracts the element out of a
Just
and throws an error if its argument is
Nothing.
Examples
Basic usage:
>>> fromJust (Just 1)
1
>>> 2 * (fromJust (Just 10))
20
>>> 2 * (fromJust Nothing)
*** Exception: Maybe.fromJust: Nothing
...
fromJust but with a better error message if it fails. Use
this only where it shouldn't fail!
Converts a Maybe into a value or throws an error if the Maybe is
Nothing.
Converts exceptional divergence to non-termination.
O(1) First element without checking if the vector is empty
O(1) Last element without checking if the vector is empty
First element of vector.
Examples:
>>> import Data.Vector.Fixed.Boxed (Vec3)
>>> let x = mk3 1 2 3 :: Vec3 Int
>>> head x
1
Extracts
Monoid value from
Maybe returning
mempty
if
Nothing.
>>> maybeToMonoid (Just [1,2,3] :: Maybe [Int])
[1,2,3]
>>> maybeToMonoid (Nothing :: Maybe [Int])
[]
Extracts
Monoid value from
Maybe returning
mempty
if
Nothing.
>>> maybeToMonoid (Just [1,2,3] :: Maybe [Int])
[1,2,3]
>>> maybeToMonoid (Nothing :: Maybe [Int])
[]
The largest element of a non-empty structure.
This function is non-total and will raise a runtime exception if the
structure happens to be empty. A structure that supports random access
and maintains its elements in order should provide a specialised
implementation to return the maximum in faster than linear time.
Examples
Basic usage:
>>> maximum [1..10]
10
>>> maximum []
*** Exception: Prelude.maximum: empty list
>>> maximum Nothing
*** Exception: maximum: empty structure
WARNING: This function is partial for possibly-empty structures like
lists.
The least element of a non-empty structure.
This function is non-total and will raise a runtime exception if the
structure happens to be empty. A structure that supports random access
and maintains its elements in order should provide a specialised
implementation to return the minimum in faster than linear time.
Examples
Basic usage:
>>> minimum [1..10]
1
>>> minimum []
*** Exception: Prelude.minimum: empty list
>>> minimum Nothing
*** Exception: minimum: empty structure
WARNING: This function is partial for possibly-empty structures like
lists.
The largest element of a non-empty structure.