Commit cfe79fd3 authored by aljee@hyper.cx's avatar aljee@hyper.cx Committed by Joachim Breitner
Browse files

Add fusion RULES for mapMaybe

parent 160fb4ce
......@@ -126,4 +126,16 @@ mapMaybe f (x:xs) =
case f x of
Nothing -> rs
Just r -> r:rs
{-# NOINLINE [1] mapMaybe #-}
{-# RULES
"mapMaybe" [~1] forall f xs. mapMaybe f xs
= build (\c n -> foldr (mapMaybeFB c f) n xs)
"mapMaybeList" [1] forall f. foldr (mapMaybeFB (:) f) [] = mapMaybe f
#-}
{-# NOINLINE [0] mapMaybeFB #-}
mapMaybeFB :: (b -> r -> r) -> (a -> Maybe b) -> a -> r -> r
mapMaybeFB cons f x next = case f x of
Nothing -> next
Just r -> cons r next
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment