39 lines
746 B
Rust
39 lines
746 B
Rust
use super::*;
|
|
|
|
/// Represents iteration state.
|
|
pub enum IState<P, D> {
|
|
/// Loop running.
|
|
Pending(P),
|
|
/// Loop finished.
|
|
Done(D),
|
|
}
|
|
|
|
pub struct IStateClass<P>(P);
|
|
|
|
impl<P> WeakFunctor for IStateClass<P> {
|
|
type F<'a, A: 'a> = IState<P, A>
|
|
where
|
|
Self: 'a;
|
|
}
|
|
|
|
impl<P> Functor for IStateClass<P> {
|
|
fn fmap<'a, A: 'a, B: 'a>(f: impl 'a + FnOnce(A) -> B, fa: Self::F<'a, A>) -> Self::F<'a, B>
|
|
where
|
|
Self: 'a,
|
|
{
|
|
match fa {
|
|
IState::Pending(p) => IState::Pending(p),
|
|
IState::Done(d) => IState::Done(f(d)),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<P> Pure for IStateClass<P> {
|
|
fn pure<'a, A: 'a>(a: A) -> Self::F<'a, A>
|
|
where
|
|
Self: 'a,
|
|
{
|
|
IState::Done(a)
|
|
}
|
|
}
|