From: sof Date: Sun, 18 May 1997 04:56:05 +0000 (+0000) Subject: [project @ 1997-05-18 04:56:05 by sof] X-Git-Tag: Approximately_1000_patches_recorded~648 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=62a2c335be9c3f33cd7d459d5403ea94b148c5ea;p=ghc-hetmet.git [project @ 1997-05-18 04:56:05 by sof] new function: mapMaybe --- diff --git a/ghc/compiler/utils/Maybes.lhs b/ghc/compiler/utils/Maybes.lhs index a3834fd..2542141 100644 --- 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(..), + 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