File tree 1 file changed +8
-0
lines changed
1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -206,24 +206,32 @@ instance
206
206
catchError = Accum. liftCatch catchError
207
207
208
208
-- | 'MonadError' analogue to the 'Control.Exception.try' function.
209
+ --
210
+ -- @since 2.3
209
211
tryError :: MonadError e m => m a -> m (Either e a )
210
212
tryError action = (Right <$> action) `catchError` (pure . Left )
211
213
212
214
-- | 'MonadError' analogue to the 'withExceptT' function.
213
215
-- Modify the value (but not the type) of an error. The type is
214
216
-- fixed because of the functional dependency @m -> e@. If you need
215
217
-- to change the type of @e@ use 'mapError' or 'modifyError'.
218
+ --
219
+ -- @since 2.3
216
220
withError :: MonadError e m => (e -> e ) -> m a -> m a
217
221
withError f action = tryError action >>= either (throwError . f) pure
218
222
219
223
-- | As 'handle' is flipped 'Control.Exception.catch', 'handleError'
220
224
-- is flipped 'catchError'.
225
+ --
226
+ -- @since 2.3
221
227
handleError :: MonadError e m => (e -> m a ) -> m a -> m a
222
228
handleError = flip catchError
223
229
224
230
-- | 'MonadError' analogue of the 'mapExceptT' function. The
225
231
-- computation is unwrapped, a function is applied to the @Either@, and
226
232
-- the result is lifted into the second 'MonadError' instance.
233
+ --
234
+ -- @since 2.3
227
235
mapError :: (MonadError e m , MonadError e' n ) => (m (Either e a ) -> n (Either e' b )) -> m a -> n b
228
236
mapError f action = f (tryError action) >>= liftEither
229
237
You can’t perform that action at this time.
0 commit comments