1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use super::{controlflow::BindableMut, *};

pub trait MonadExt<'a>: Monad<'a> {
    /// [`FnMut`] version of [`Monad::iterate`].
    /// Reasoning for this method existing at all is that
    /// most usecases are better modelled with [`FnMut`]
    /// rather than some dedicated state type.
    fn iterate_mut<A: 'a + Send, B: 'a + Send>(
        a: A,
        f: impl 'a + Send + FnMut(A) -> Self::F<ControlFlow<B, A>>,
    ) -> Self::F<B> {
        Self::iterate(BindableMut::new(a, f))
    }

    fn bind2<A: 'a + Send, B: 'a + Send, C: 'a + Send>(
        fa: Self::F<A>,
        fb: Self::F<B>,
        f: impl 'a + Send + FnOnce(A, B) -> Self::F<C>,
    ) -> Self::F<C> {
        Self::join(Self::la2(fa, fb, f))
    }
}

impl<'a, T: Monad<'a>> MonadExt<'a> for T {}