-
-
Save bjorn3/88fb8a7177b35acd2d77f8dcabd725c7 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Kind<T> { | |
type Make; | |
} | |
enum OptionKind {} | |
impl<T> Kind<T> for OptionKind { | |
type Make = Option<T>; | |
} | |
trait FunctorKind<A, B>: Kind<A> + Kind<B> { | |
fn fmapk(<Self as Kind<A>>::Make, impl Fn(A) -> B) -> <Self as Kind<B>>::Make; | |
} | |
impl<A, B> FunctorKind<A, B> for OptionKind { | |
fn fmapk(me: Option<A>, f: impl Fn(A) -> B) -> Option<B> { | |
match me { | |
Some(m) => Some(f(m)), | |
None => None, | |
} | |
} | |
} | |
fn main() { | |
println!("{:?}", OptionKind::fmapk(Some(10), |a| a + 1)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment