lubeck 0.0.0-prealpha.5-abandoned

Functional programming framework written in cutting edge rust
Documentation
use crate::prelude::Applicative;

use super::def::State;

impl<'a, S, A> Applicative<'a, A> for State<'a, S, A>
where
    S: Clone + 'a,
    A: 'a,
{
    type PureT<T> = T where T:'a;

    fn pure(a: Self::PureT<A>) -> Self::Type<Self::PureT<A>> {
        Self::Type::<Self::PureT<A>> {
            run_state: Some(Box::new(move |s| (a, s))),
        }
    }

    fn app<F, B>(self, f: Self::Type<F>) -> Self::Type<B>
    where
        F: Fn(A) -> B + 'a,
        B: 'a,
    {
        Self::Type::<B> {
            run_state: Some(Box::new(move |s| {
                // S -> (A, S)
                let (a, st) = self.run(s);
                // S -> (F, S)
                let (f, stt) = f.run(st);
                // (A, S) -> (B, S)
                let (b, stt) = (f(a), stt);
                (b, stt)
            })),
        }
    }
}