Derive Macro timrs_hkt_macro::HKT
source · #[derive(HKT)]
Expand description
Macro for deriving implementations of crate::hkt!
.
Arity of the Higher-Kinded Type is automatically defined based on the implementing type arity.
§Examples
use timrs_hkt_macro::{hkt, HKT};
/* The parameter indicates the arity of the Higher-Kinded Type trait to be generated */
hkt!(1);
trait Functor: HKT1 {
fn map<B, F>(self, f: F) -> Self::With<B>
where
F: FnMut(Self::T1) -> B;
}
#[derive(HKT, Debug, PartialEq)]
enum Example1<A> {
First(A),
}
impl<A> Functor for Example1<A> {
fn map<B, F>(self, mut f: F) -> Self::With<B>
where
F: FnMut(Self::T1) -> B,
{
match self {
Self::First(a) => Example1::First(f(a)),
}
}
}
assert_eq!(
Example1::First("The magic number is 42".to_owned()),
Example1::First(42).map(|x| "The magic number is ".to_owned() + &x.to_string())
);