void_can_be_exressed_via_replace
All checks were successful
buildbot/cargo fmt (1.72) Build done.
buildbot/cargo clippy (1.72) Build done.
buildbot/cargo doc (1.72) Build done.
buildbot/cargo test (1.65) Build done.
buildbot/cargo clippy (1.65) Build done.

This commit is contained in:
AF 2023-10-15 14:26:40 +00:00
parent ad5361cfbf
commit f8d8a77b1f
2 changed files with 17 additions and 0 deletions

View File

@ -75,5 +75,8 @@ pub fn monad_follows_laws<'a, T: Monad<'a> + FunctorTestSuite<'a>>() -> R {
T::sample(|pa| {
res += fmap_can_be_expressed_via_bind::<T, _, _>(|x| x + 3, || pa(2));
});
T::sample(|pa| {
res += void_can_be_exressed_via_replace::<T, _>(|| pa(2));
});
res
}

View File

@ -317,3 +317,17 @@ pub fn fmap_can_be_expressed_via_bind<
T::bind(fa0(), move |a| T::pure(f(a))),
)
}
pub fn void_can_be_exressed_via_replace<
'a,
T: Monad<'a> + Eqr<'a>,
A: 'a + Send + Debug + PartialEq,
>(
fa0: impl Fn() -> T::F<A>,
) -> R {
T::eqr(
"void via bind: void x = () <$ x",
T::void(fa0()),
T::replace(fa0(), ()),
)
}