File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -206,24 +206,32 @@ instance
206206 catchError = Accum. liftCatch catchError
207207
208208-- | 'MonadError' analogue to the 'Control.Exception.try' function.
209+ --
210+ -- @since 2.3
209211tryError :: MonadError e m => m a -> m (Either e a )
210212tryError action = (Right <$> action) `catchError` (pure . Left )
211213
212214-- | 'MonadError' analogue to the 'withExceptT' function.
213215-- Modify the value (but not the type) of an error. The type is
214216-- fixed because of the functional dependency @m -> e@. If you need
215217-- to change the type of @e@ use 'mapError' or 'modifyError'.
218+ --
219+ -- @since 2.3
216220withError :: MonadError e m => (e -> e ) -> m a -> m a
217221withError f action = tryError action >>= either (throwError . f) pure
218222
219223-- | As 'handle' is flipped 'Control.Exception.catch', 'handleError'
220224-- is flipped 'catchError'.
225+ --
226+ -- @since 2.3
221227handleError :: MonadError e m => (e -> m a ) -> m a -> m a
222228handleError = flip catchError
223229
224230-- | 'MonadError' analogue of the 'mapExceptT' function. The
225231-- computation is unwrapped, a function is applied to the @Either@, and
226232-- the result is lifted into the second 'MonadError' instance.
233+ --
234+ -- @since 2.3
227235mapError :: (MonadError e m , MonadError e' n ) => (m (Either e a ) -> n (Either e' b )) -> m a -> n b
228236mapError f action = f (tryError action) >>= liftEither
229237
You can’t perform that action at this time.
0 commit comments