Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created December 9, 2020 23:48
Show Gist options
  • Save rust-play/43200608c0a841165c57ab660029b4f1 to your computer and use it in GitHub Desktop.
Save rust-play/43200608c0a841165c57ab660029b4f1 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
#![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