readMaybe

Parse a string using the Read instance. Succeeds if there is exactly one valid result.
>>> readMaybe "123" :: Maybe Int
Just 123
>>> readMaybe "hello" :: Maybe Int
Nothing
Yield the element at the given position. Returns Nothing if the index is out of range.

Examples

>>> import qualified Data.Vector.Strict.Mutable as MV

>>> v <- MV.generate 10 (\x -> x*x)

>>> MV.readMaybe v 3
Just 9

>>> MV.readMaybe v 13
Nothing
Yield the element at the given position. Returns Nothing if the index is out of range.

Examples

>>> import qualified Data.Vector.Mutable as MV

>>> v <- MV.generate 10 (\x -> x*x)

>>> MV.readMaybe v 3
Just 9

>>> MV.readMaybe v 13
Nothing
Yield the element at the given position. Returns Nothing if the index is out of range.

Examples

>>> import qualified Data.Vector.Primitive.Mutable as MVP

>>> v <- MVP.generate 10 (\x -> x*x)

>>> MVP.readMaybe v 3
Just 9

>>> MVP.readMaybe v 13
Nothing
Yield the element at the given position. Returns Nothing if the index is out of range.

Examples

>>> import qualified Data.Vector.Storable.Mutable as MVS

>>> v <- MVS.generate 10 (\x -> x*x)

>>> MVS.readMaybe v 3
Just 9

>>> MVS.readMaybe v 13
Nothing
Yield the element at the given position. Returns Nothing if the index is out of range.

Examples

>>> import qualified Data.Vector.Unboxed.Mutable as MVU

>>> v <- MVU.generate 10 (\x -> x*x)

>>> MVU.readMaybe v 3
Just 9

>>> MVU.readMaybe v 13
Nothing
Parse a string using the Read instance. Succeeds if there is exactly one valid result.
>>> readMaybe ("123" :: Text) :: Maybe Int
Just 123
>>> readMaybe ("hello" :: Text) :: Maybe Int
Nothing
Parse a string using the Read instance. Succeeds if there is exactly one valid result.
>>> readMaybe "123" :: Maybe Int
Just 123
>>> readMaybe "hello" :: Maybe Int
Nothing
@since base-4.6.0.0
Inspired by the: https://hackage.haskell.org/package/base-4.14.0.0/docs/Data-Maybe.html Is provided here as a more general way to read the String into a EncodedCnstrs. It is up to user to check whether the parameters are in the correct form, the function does not do the full checking.
>>> greadMaybe "InL Refl" mkSome :: Maybe (Some (Sum ((:~:) Int) ((:~:) Bool)))
Just (mkSome (InL Refl))
>>> greadMaybe "L1 Refl" mkSome :: Maybe (Some ((:~:) Int :+: (:~:) Bool))
Just (mkSome (L1 Refl))
>>> greadMaybe "garbage" mkSome :: Maybe (Some ((:~:) Int))
Nothing