Skip to content
Snippets Groups Projects
Commit 62a2c335 authored by sof's avatar sof
Browse files

[project @ 1997-05-18 04:56:05 by sof]

new function: mapMaybe
parent cf4ec401
No related merge requests found
......@@ -12,6 +12,7 @@ module Maybes (
-- Maybe(..), -- no, it's in 1.3
MaybeErr(..),
mapMaybe,
allMaybes,
firstJust,
expectJust,
......@@ -80,6 +81,12 @@ allMaybes (Nothing : ms) = Nothing
allMaybes (Just x : ms) = case (allMaybes ms) of
Nothing -> Nothing
Just xs -> Just (x:xs)
mapMaybe :: (a -> Maybe b) -> [a] -> [b]
mapMaybe f [] = []
mapMaybe f (x:xs) = case f x of
Just y -> y : mapMaybe f xs
Nothing -> mapMaybe f xs
\end{code}
@firstJust@ takes a list of @Maybes@ and returns the
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment