Hoogle Search
Within LTS Haskell 24.49 (ghc-9.10.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
-
protolude Protolude The listToMaybe function returns Nothing on an empty list or Just a where a 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]
mapMaybe :: (a -> Maybe b) -> [a] -> [b]protolude Protolude The mapMaybe function is a version of map which can throw out elements. In particular, the functional argument returns something of type Maybe b. If this is Nothing, no element is added on to the result list. If it is Just b, then b is included in the result list.
Examples
Using mapMaybe f x is a shortcut for catMaybes $ map f x in most cases:>>> import GHC.Internal.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]
readMaybe :: (Read b, StringConv a String) => a -> Maybe bprotolude Protolude 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 NothingleftToMaybe :: Either l r -> Maybe lprotolude Protolude.Either No documentation available.
rightToMaybe :: Either l r -> Maybe rprotolude Protolude.Either No documentation available.
mapMaybeNoNull :: (a -> Maybe b) -> MonoidalMap token a -> Maybe (MonoidalMap token b)reflex Data.AppendMap Like mapMaybe but indicates whether the resulting container is empty
class
FunctorMaybe (f :: Type -> Type)reflex Reflex.Class Deprecated: Use Filterable from Data.Witherable instead
-
reflex Reflex.Class No documentation available.
-
reflex Reflex.Class No documentation available.
fforMaybe :: Filterable f => f a -> (a -> Maybe b) -> f breflex Reflex.Class Flipped version of mapMaybe.