-
-
Save rust-play/43200608c0a841165c57ab660029b4f1 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
#![feature(generic_associated_types)] | |
trait Monad { | |
type Unwrapped; | |
type Wrapped<B>; | |
fn bind<B, F>(self, f: F) -> Self::Wrapped<B> { | |
todo!() | |
} | |
} | |
fn join<MOuter, MInner, A>(outer: MOuter) -> MOuter::Wrapped<A> | |
where | |
MOuter: Monad<Unwrapped = MInner>, | |
MInner: Monad<Unwrapped = A, Wrapped = MOuter::Wrapped<A>>, | |
{ | |
outer.bind(|inner| inner) | |
} | |
fn main() { | |
assert_eq!(join(Some(Some(true))), Some(true)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment