projects
/
ghc-hetmet.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
cf4ec40
)
[project @ 1997-05-18 04:56:05 by sof]
author
sof
<unknown>
Sun, 18 May 1997 04:56:05 +0000
(
04:56
+0000)
committer
sof
<unknown>
Sun, 18 May 1997 04:56:05 +0000
(
04:56
+0000)
new function: mapMaybe
ghc/compiler/utils/Maybes.lhs
patch
|
blob
|
history
diff --git
a/ghc/compiler/utils/Maybes.lhs
b/ghc/compiler/utils/Maybes.lhs
index
a3834fd
..
2542141
100644
(file)
--- a/
ghc/compiler/utils/Maybes.lhs
+++ b/
ghc/compiler/utils/Maybes.lhs
@@
-12,6
+12,7
@@
module Maybes (
-- Maybe(..), -- no, it's in 1.3
MaybeErr(..),
-- Maybe(..), -- no, it's in 1.3
MaybeErr(..),
+ mapMaybe,
allMaybes,
firstJust,
expectJust,
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)
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
\end{code}
@firstJust@ takes a list of @Maybes@ and returns the