join_can_be_expressed_via_bind
This commit is contained in:
parent
106fd83e33
commit
2badeb7f01
@ -83,5 +83,10 @@ pub fn monad_follows_laws<'a, T: Monad<'a> + FunctorTestSuite<'a>>() -> R {
|
|||||||
T::sample(|pa| {
|
T::sample(|pa| {
|
||||||
res += fmap_can_be_expressed_via_bind::<T, _, _>(|x| x + 3, || pa(2));
|
res += fmap_can_be_expressed_via_bind::<T, _, _>(|x| x + 3, || pa(2));
|
||||||
});
|
});
|
||||||
|
T::sample(|pa| {
|
||||||
|
T::sample(|pb| {
|
||||||
|
res += join_can_be_expressed_via_bind::<T, _>(|| pa(pb(2)));
|
||||||
|
})
|
||||||
|
});
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
@ -347,3 +347,17 @@ pub fn tuple_can_be_expressed_via_la2<
|
|||||||
T::la2(fa0(), fb0(), |a, b| (a, b)),
|
T::la2(fa0(), fb0(), |a, b| (a, b)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn join_can_be_expressed_via_bind<
|
||||||
|
'a,
|
||||||
|
T: Monad<'a> + Eqr<'a>,
|
||||||
|
A: 'a + Send + Debug + PartialEq,
|
||||||
|
>(
|
||||||
|
ffa0: impl Fn() -> T::F<T::F<A>>,
|
||||||
|
) -> R {
|
||||||
|
T::eqr(
|
||||||
|
"join via bind: join x = x >>= id",
|
||||||
|
T::join(ffa0()),
|
||||||
|
T::bind(ffa0(), |fa| fa),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user