MonadFailAny::map_err
This commit is contained in:
		
							parent
							
								
									4d6cfaac1c
								
							
						
					
					
						commit
						5d604d2834
					
				
							
								
								
									
										11
									
								
								src/func.rs
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/func.rs
									
									
									
									
									
								
							| @ -199,7 +199,8 @@ pub trait MonadFail<E>: Monad { | ||||
|     /// Equivalent of Haskell's `fail`.
 | ||||
|     fn fail<'a, A: 'a>(e: E) -> Self::F<'a, A> | ||||
|     where | ||||
|         Self: 'a; | ||||
|         Self: 'a, | ||||
|         E: 'a; | ||||
| } | ||||
| 
 | ||||
| /// Equivalent of Haskell's `Alternative`.
 | ||||
| @ -238,6 +239,14 @@ pub trait LocalFunctor: WeakFunctor { | ||||
| pub trait MonadFailAny { | ||||
|     /// [`MonadFail`] for a specific error type.
 | ||||
|     type W<E>: MonadFail<E>; | ||||
| 
 | ||||
|     /// Equivalent of [`Result::map_err`].
 | ||||
|     fn map_err<'a, A: 'a, E0: 'a, E1: 'a>( | ||||
|         wa: <Self::W<E0> as WeakFunctor>::F<'a, A>, | ||||
|         f: impl 'a + FnOnce(E0) -> E1, | ||||
|     ) -> <Self::W<E1> as WeakFunctor>::F<'a, A> | ||||
|     where | ||||
|         Self: 'a; | ||||
| } | ||||
| 
 | ||||
| /// Represents a (collection of) [Monad]\(s),
 | ||||
|  | ||||
| @ -125,6 +125,7 @@ impl<E, U: Monad, V: MonadFail<E> + LocalFunctor> MonadFail<E> for CompositionCl | ||||
|     fn fail<'a, A: 'a>(e: E) -> Self::F<'a, A> | ||||
|     where | ||||
|         Self: 'a, | ||||
|         E: 'a, | ||||
|     { | ||||
|         U::pure(V::fail(e)) | ||||
|     } | ||||
|  | ||||
| @ -163,6 +163,16 @@ pub struct ResultFailAny; | ||||
| 
 | ||||
| impl MonadFailAny for ResultFailAny { | ||||
|     type W<E> = ResultClass<E>; | ||||
| 
 | ||||
|     fn map_err<'a, A: 'a, E0: 'a, E1: 'a>( | ||||
|         wa: <Self::W<E0> as WeakFunctor>::F<'a, A>, | ||||
|         f: impl 'a + FnOnce(E0) -> E1, | ||||
|     ) -> <Self::W<E1> as WeakFunctor>::F<'a, A> | ||||
|     where | ||||
|         Self: 'a, | ||||
|     { | ||||
|         wa.map_err(f) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl MonadFailOver<classes::solo::SoloClass> for ResultFailAny { | ||||
| @ -191,6 +201,16 @@ pub struct ResultFailOver<T: Monad>(T); | ||||
| 
 | ||||
| impl<T: Monad> MonadFailAny for ResultFailOver<T> { | ||||
|     type W<E> = super::composition::CompositionClass<T, ResultClass<E>>; | ||||
| 
 | ||||
|     fn map_err<'a, A: 'a, E0: 'a, E1: 'a>( | ||||
|         wa: <Self::W<E0> as WeakFunctor>::F<'a, A>, | ||||
|         f: impl 'a + FnOnce(E0) -> E1, | ||||
|     ) -> <Self::W<E1> as WeakFunctor>::F<'a, A> | ||||
|     where | ||||
|         Self: 'a, | ||||
|     { | ||||
|         T::fmap(|a| a.map_err(f), wa) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl<T: Monad> MonadFailOver<T> for ResultFailOver<T> { | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user