more specific replace/void for option/result

This commit is contained in:
AF 2023-04-26 16:29:00 +00:00
parent a32ae322b1
commit 2e9d1ac221
2 changed files with 22 additions and 3 deletions

View File

@ -21,8 +21,19 @@ impl Functor for OptionClass {
fa.map(f)
}
fn replace<'a, A: 'a, B: 'a>(fa: Self::F<'a, A>, b: B) -> Self::F<'a, B> {
fa.map(|_| b)
fn replace<'a, A: 'a, B: 'a>(fa: Self::F<'a, A>, b: B) -> Self::F<'a, B>
where
Self: 'a,
{
fa?;
Self::pure(b)
}
fn void<'a, A: 'a>(fa: Self::F<'a, A>) -> Self::F<'a, ()>
where
Self: 'a, {
fa?;
Self::pure(())
}
}

View File

@ -28,7 +28,15 @@ impl<E> Functor for ResultClass<E> {
where
Self: 'a,
{
fa.map(|_| b)
fa?;
Self::pure(b)
}
fn void<'a, A: 'a>(fa: Self::F<'a, A>) -> Self::F<'a, ()>
where
Self: 'a, {
fa?;
Self::pure(())
}
}