rio-0.1.22.0: A standard library for Haskell

Safe Haskell | Safe-Inferred
Language | Haskell2010

RIO.Partial

Description

Partial functions. Import as:

    import qualified RIO.Partial as RIO'

Synopsis

- fromJust :: HasCallStack => Maybe a -> a
- read :: Read a => String -> a
- toEnum :: Enum a => Int -> a
- pred :: Enum a => a -> a
- succ :: Enum a => a -> a

# Documentation

fromJust :: HasCallStack => Maybe a -> a #

The `fromJust` function extracts the element out of a `Just` and throws an error if its argument is `Nothing`.

#### Examples

Expand

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.

read :: Read a => String -> a #

The `read` function reads input from a string, which must be completely consumed by the input process. `read` fails with an `error` if the parse is unsuccessful, and it is therefore discouraged from being used in real applications. Use `readMaybe` or `readEither` for safe alternatives.

    >>> read "123" :: Int
    123

    >>> read "hello" :: Int
    *** Exception: Prelude.read: no parse

toEnum :: Enum a => Int -> a #

Convert from an `Int`.

pred :: Enum a => a -> a #

the predecessor of a value. For numeric types, `pred` subtracts 1.

succ :: Enum a => a -> a #

the successor of a value. For numeric types, `succ` adds 1.