macro_rules! functor { ($name:ident<A $(, $($g_ty:ident $(: $g_bound:path $(, $g_bounds:path)*)?),+)?>: fn fmap($self:ident, $f:ident) $fmap:block) => { ... }; }
Expand description
Implement Functor (and its superclasses automatically) after a definition.
use rsmonad::prelude::*;
#[derive(Debug, PartialEq)]
struct Pointless<A>(A);
functor! {
Pointless<A>:
fn fmap(self, f) {
Pointless(f(self.0))
}
}
assert_eq!(Pointless(4) % u8::is_power_of_two, Pointless(true));