orElse,
mapCatMaybes,
allMaybes,
- firstJust,
+ firstJust, firstJusts,
expectJust,
maybeToBool,
Nothing -> Nothing
Just xs -> Just (x:xs)
+firstJust :: Maybe a -> Maybe a -> Maybe a
+firstJust (Just a) _ = Just a
+firstJust Nothing b = b
+
-- | Takes a list of @Maybes@ and returns the first @Just@ if there is one, or
-- @Nothing@ otherwise.
-firstJust :: [Maybe a] -> Maybe a
-firstJust [] = Nothing
-firstJust (Just x : _) = Just x
-firstJust (Nothing : ms) = firstJust ms
+firstJusts :: [Maybe a] -> Maybe a
+firstJusts = foldr firstJust Nothing
\end{code}
\begin{code}
\end{code}
\begin{code}
+
orElse :: Maybe a -> a -> a
(Just x) `orElse` _ = x
Nothing `orElse` y = y