Skip to content

Instantly share code, notes, and snippets.

@charlesetc
Created April 21, 2016 06:48
Show Gist options
  • Save charlesetc/32a5c5be1f1edf1d9d2ca644c50a86cf to your computer and use it in GitHub Desktop.
Save charlesetc/32a5c5be1f1edf1d9d2ca644c50a86cf to your computer and use it in GitHub Desktop.
#[macro_export]
macro_rules! then {
($op1:expr => $op2:expr) => {
Monad::bind($op1, Box::new(move |_| {
$op2
}))
}
}
// Kind of like `do` notation in haskell.
#[macro_export]
macro_rules! perform {
($e:expr ; $($rest:tt)+) => ({{
then!($e => perform!($($rest)*));
}});
($b:expr => $a:ident ; $($rest:tt)*) => ({
Monad::bind($b, Box::new(move |$a| {
perform!($($rest)*)
}))
});
($e:expr ; ) => { $e; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment