Skip to content

Instantly share code, notes, and snippets.

Created July 1, 2015 22:23
Show Gist options
  • Save anonymous/a3c8b998f1e96872994b to your computer and use it in GitHub Desktop.
Save anonymous/a3c8b998f1e96872994b to your computer and use it in GitHub Desktop.
Shared via Rust Playground
fn f(a: u8) -> Option<u16> { unimplemented!() }
fn g(b: u16) -> Option<u32> { unimplemented!() }
fn h(c: u32) -> Option<u64> { unimplemented!() }
fn do_something_with(a: u8, b: u16, c: u32, d: u64) -> Option<()> { unimplemented!() }
macro_rules! get(
($e:expr) => (match $e { Some(e) => e, None => return None })
);
fn blah1() {
let a = 123;
f(a).and_then(|b| {
g(b).and_then(|c| {
h(c).map(|d| {
do_something_with(a, b, c, d)
})
})
});
}
fn blah2() -> Option<()> {
let a = 123;
let b = get!(f(a));
let c = get!(g(b));
let d = get!(h(c));
do_something_with(a, b, c, d)
}
fn main() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment