#[fp_macros::document_module]
mod inner {
use {
crate::{
classes::*,
kinds::*,
},
fp_macros::*,
};
#[document_examples]
pub trait Choice: Profunctor {
#[document_signature]
#[document_type_parameters(
"The lifetime of the values.",
"The input type of the profunctor.",
"The output type of the profunctor.",
"The type of the alternative variant (threaded through unchanged)."
)]
#[document_parameters("The profunctor instance to lift.")]
#[document_returns("A new profunctor that operates on Result types.")]
#[document_examples]
fn left<'a, A: 'a, B: 'a, C: 'a>(
pab: Apply!(<Self as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, A, B>)
) -> Apply!(<Self as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, Result<C, A>, Result<C, B>>);
#[document_signature]
#[document_type_parameters(
"The lifetime of the values.",
"The input type of the profunctor.",
"The output type of the profunctor.",
"The type of the alternative variant (threaded through unchanged)."
)]
#[document_parameters("The profunctor instance to lift.")]
#[document_returns("A new profunctor that operates on Result types.")]
#[document_examples]
fn right<'a, A: 'a, B: 'a, C: 'a>(
pab: Apply!(<Self as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, A, B>)
) -> Apply!(<Self as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, Result<A, C>, Result<B, C>>)
{
Self::dimap(
|r: Result<A, C>| match r {
Ok(a) => Err(a),
Err(c) => Ok(c),
},
|r: Result<C, B>| match r {
Ok(c) => Err(c),
Err(b) => Ok(b),
},
Self::left(pab),
)
}
}
#[document_signature]
#[document_type_parameters(
"The lifetime of the values.",
"The brand of the choice profunctor.",
"The input type of the profunctor.",
"The output type of the profunctor.",
"The type of the alternative variant (threaded through unchanged)."
)]
#[document_parameters("The profunctor instance to lift.")]
#[document_returns("A new profunctor that operates on Result types.")]
#[document_examples]
pub fn left<'a, Brand: Choice, A: 'a, B: 'a, C: 'a>(
pab: Apply!(<Brand as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, A, B>)
) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, Result<C, A>, Result<C, B>>)
{
Brand::left(pab)
}
#[document_signature]
#[document_type_parameters(
"The lifetime of the values.",
"The brand of the choice profunctor.",
"The input type of the profunctor.",
"The output type of the profunctor.",
"The type of the alternative variant (threaded through unchanged)."
)]
#[document_parameters("The profunctor instance to lift.")]
#[document_returns("A new profunctor that operates on Result types.")]
#[document_examples]
pub fn right<'a, Brand: Choice, A: 'a, B: 'a, C: 'a>(
pab: Apply!(<Brand as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, A, B>)
) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, Result<A, C>, Result<B, C>>)
{
Brand::right(pab)
}
#[document_signature]
#[document_type_parameters(
"The lifetime of the values.",
"The brand of the choice profunctor.",
"The input type of the Err-side profunctor.",
"The output type of the Err-side profunctor.",
"The input type of the Ok-side profunctor.",
"The output type of the Ok-side profunctor."
)]
#[document_parameters(
"The profunctor acting on the Err variant.",
"The profunctor acting on the Ok variant."
)]
#[document_returns("A new profunctor that maps `l` over `Err` and `r` over `Ok`.")]
#[document_examples]
pub fn split_choice<'a, Brand: Semigroupoid + Choice, A: 'a, B: 'a, C: 'a, D: 'a>(
l: Apply!(<Brand as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, A, B>),
r: Apply!(<Brand as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, C, D>),
) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, Result<C, A>, Result<D, B>>)
{
Brand::compose(Brand::right(r), Brand::left(l))
}
#[document_signature]
#[document_type_parameters(
"The lifetime of the values.",
"The brand of the choice profunctor.",
"The Err-side input type.",
"The Ok-side input type.",
"The shared output type."
)]
#[document_parameters(
"The profunctor handling the Err variant.",
"The profunctor handling the Ok variant."
)]
#[document_returns(
"A new profunctor that eliminates the sum by routing each variant to the appropriate handler."
)]
#[document_examples]
pub fn fan_in<'a, Brand: Semigroupoid + Choice, A: 'a, B: 'a, C: 'a>(
l: Apply!(<Brand as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, A, C>),
r: Apply!(<Brand as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, B, C>),
) -> Apply!(<Brand as Kind!( type Of<'a, T: 'a, U: 'a>: 'a; )>::Of<'a, Result<B, A>, C>) {
Brand::map_output(
|result: Result<C, C>| match result {
Ok(c) | Err(c) => c,
},
split_choice::<Brand, A, C, B, C>(l, r),
)
}
}
pub use inner::*;