Commit 66f0056a authored by Simon Jakobi's avatar Simon Jakobi Committed by Ben Gamari

Refactor TcRnMonad.mapAndRecoverM

This version doesn't require the 'reverse' step after the monadic
fold.

Test Plan: ./validate

Reviewers: bgamari, tdammers

Reviewed By: tdammers

Subscribers: monoidal, rwbarton, carter

Differential Revision: https://phabricator.haskell.org/D5343
parent 390df8b5
......@@ -990,7 +990,7 @@ recoverM recover thing
-- | Drop elements of the input that fail, so the result
-- list can be shorter than the argument list
mapAndRecoverM :: (a -> TcRn b) -> [a] -> TcRn [b]
mapAndRecoverM f = fmap reverse . foldAndRecoverM (\xs x -> (:xs) <$> f x ) []
mapAndRecoverM f = mapMaybeM (fmap rightToMaybe . try_m . f)
-- | The accumulator is not updated if the action fails
foldAndRecoverM :: (b -> a -> TcRn b) -> b -> [a] -> TcRn b
......
......@@ -18,6 +18,7 @@ module Maybes (
firstJust, firstJusts,
whenIsJust,
expectJust,
rightToMaybe,
-- * MaybeT
MaybeT(..), liftMaybeT, tryMaybeT
......@@ -62,6 +63,10 @@ whenIsJust Nothing _ = return ()
orElse :: Maybe a -> a -> a
orElse = flip fromMaybe
rightToMaybe :: Either a b -> Maybe b
rightToMaybe (Left _) = Nothing
rightToMaybe (Right x) = Just x
{-
************************************************************************
* *
......
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