From 62a2c335be9c3f33cd7d459d5403ea94b148c5ea Mon Sep 17 00:00:00 2001 From: sof Date: Sun, 18 May 1997 04:56:05 +0000 Subject: [PATCH] [project @ 1997-05-18 04:56:05 by sof] new function: mapMaybe --- ghc/compiler/utils/Maybes.lhs | 7 +++++++ 1 file changed, 7 insertions(+) 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 -- 1.7.10.4