Iterative -> AIterative

This commit is contained in:
AF 2023-04-27 07:48:07 +00:00
parent 2a2ea431ac
commit 38f6aef9d0
11 changed files with 23 additions and 21 deletions

View File

@ -21,8 +21,8 @@ pub use std::ops::ControlFlow;
pub use radn_derive::{CovariantFunctor, SharedFunctor};
pub use self::controlflow::{AIterative, AIterativeWrapped};
use self::controlflow::{BindableMut, ControlFlowClass};
pub use self::controlflow::{Iterative, IterativeWrapped};
/// Part of Haskell's `Functor f` responsible for having `f a`.
///
@ -196,7 +196,7 @@ pub trait Monad: Applicative {
/// On practice, you generally shouldn't be using [`Monad::bind`]/[`Pure::pure`]/[`Functor::fmap`] here.
fn iibind<'a, A: 'a, B: 'a>(
a: A,
f: impl Iterative<'a, T = Self, A = A, B = B>,
f: impl AIterative<'a, T = Self, A = A, B = B>,
) -> Self::F<'a, B>
where
Self: 'a;

View File

@ -114,7 +114,7 @@ impl<U: Monad, V: Monad + LocalFunctor> Monad for CompositionClass<U, V> {
fn iibind<'a, A: 'a, B: 'a>(
a: A,
f: impl Iterative<'a, T = Self, A = A, B = B>,
f: impl AIterative<'a, T = Self, A = A, B = B>,
) -> Self::F<'a, B>
where
Self: 'a,
@ -137,14 +137,14 @@ impl<
'a,
U: 'a + Monad,
V: 'a + Monad + LocalFunctor,
F: Iterative<'a, T = CompositionClass<U, V>>,
> Iterative<'a> for ComposedBindable<F>
F: AIterative<'a, T = CompositionClass<U, V>>,
> AIterative<'a> for ComposedBindable<F>
{
type A = F::A;
type B = <V as WeakFunctor>::F<'a, F::B>;
type T = U;
fn iterate(self, a: Self::A) -> IterativeWrapped<'a, Self> {
fn iterate(self, a: Self::A) -> AIterativeWrapped<'a, Self> {
let fstate = self.0.iterate(a);
U::fmap(
|ustate| match V::unstuff(ustate) {

View File

@ -106,7 +106,7 @@ impl Monad for FutureClass {
fn iibind<'a, A: 'a, B: 'a>(
mut a: A,
mut f: impl Iterative<'a, T = Self, A = A, B = B>,
mut f: impl AIterative<'a, T = Self, A = A, B = B>,
) -> Self::F<'a, B>
where
Self: 'a,

View File

@ -105,7 +105,7 @@ impl Monad for LazyClass {
fn iibind<'a, A: 'a, B: 'a>(
mut a: A,
mut f: impl Iterative<'a, T = Self, A = A, B = B>,
mut f: impl AIterative<'a, T = Self, A = A, B = B>,
) -> Self::F<'a, B>
where
Self: 'a,

View File

@ -109,7 +109,7 @@ impl Monad for OptionClass {
fn iibind<'a, A: 'a, B: 'a>(
mut a: A,
mut f: impl Iterative<'a, T = Self, A = A, B = B>,
mut f: impl AIterative<'a, T = Self, A = A, B = B>,
) -> Self::F<'a, B>
where
Self: 'a,

View File

@ -130,7 +130,7 @@ impl<E> Monad for ResultClass<E> {
fn iibind<'a, A: 'a, B: 'a>(
mut a: A,
mut f: impl Iterative<'a, T = Self, A = A, B = B>,
mut f: impl AIterative<'a, T = Self, A = A, B = B>,
) -> Self::F<'a, B>
where
Self: 'a,

View File

@ -97,7 +97,7 @@ impl Monad for SoloClass {
fn iibind<'a, A: 'a, B: 'a>(
mut a: A,
mut f: impl Iterative<'a, T = Self, A = A, B = B>,
mut f: impl AIterative<'a, T = Self, A = A, B = B>,
) -> Self::F<'a, B>
where
Self: 'a,

View File

@ -241,7 +241,7 @@ impl Monad for StacklessClass {
fn iibind<'a, A: 'a, B: 'a>(
a: A,
f: impl Iterative<'a, T = Self, A = A, B = B>,
f: impl AIterative<'a, T = Self, A = A, B = B>,
) -> Self::F<'a, B>
where
Self: 'a,

View File

@ -31,14 +31,16 @@ impl<C> Pure for ControlFlowClass<C> {
}
}
/// Next [Iterative] state, wrapped.
pub type IterativeWrapped<'a, G> = <<G as Iterative<'a>>::T as WeakFunctor>::F<
/// Next [AIterative] state, wrapped.
pub type AIterativeWrapped<'a, G> = <<G as AIterative<'a>>::T as WeakFunctor>::F<
'a,
ControlFlow<<G as Iterative<'a>>::B, (<G as Iterative<'a>>::A, G)>,
ControlFlow<<G as AIterative<'a>>::B, (<G as AIterative<'a>>::A, G)>,
>;
/// Value passed to [`Monad::iibind`].
pub trait Iterative<'a>: 'a + Sized {
/// `A` prefix meaning "with an **a**rgument" given current implementation
/// relying on the argument getting passed around.
pub trait AIterative<'a>: 'a + Sized {
/// [`ControlFlow::Continue`].
type A: 'a;
/// [`ControlFlow::Break`].
@ -46,7 +48,7 @@ pub trait Iterative<'a>: 'a + Sized {
/// Corresponding [`WeakFunctor`].
type T: 'a + ?Sized + WeakFunctor;
/// Get next state.
fn iterate(self, a: Self::A) -> IterativeWrapped<'a, Self>;
fn iterate(self, a: Self::A) -> AIterativeWrapped<'a, Self>;
}
pub struct BindableMut<T: ?Sized, A, B, F>(F, PhantomData<A>, PhantomData<B>, PhantomData<T>);
@ -70,13 +72,13 @@ impl<
A: 'a,
B: 'a,
F: 'a + FnMut(A) -> T::F<'a, ControlFlow<B, A>>,
> Iterative<'a> for BindableMut<T, A, B, F>
> AIterative<'a> for BindableMut<T, A, B, F>
{
type A = A;
type B = B;
type T = T;
fn iterate(mut self, a: Self::A) -> IterativeWrapped<'a, Self> {
fn iterate(mut self, a: Self::A) -> AIterativeWrapped<'a, Self> {
let fa = self.0(a);
T::fmap(
move |state| match state {

View File

@ -184,7 +184,7 @@ impl Monad for TracedClass {
fn iibind<'a, A: 'a, B: 'a>(
mut a: A,
mut f: impl Iterative<'a, T = Self, A = A, B = B>,
mut f: impl AIterative<'a, T = Self, A = A, B = B>,
) -> Self::F<'a, B>
where
Self: 'a,

View File

@ -166,7 +166,7 @@ impl Monad for CountedClass {
fn iibind<'a, A: 'a, B: 'a>(
mut a: A,
mut f: impl Iterative<'a, T = Self, A = A, B = B>,
mut f: impl AIterative<'a, T = Self, A = A, B = B>,
) -> Self::F<'a, B>
where
Self: 'a,