Comment

Comment by lower

Suppose you have two functions

    fn f() -> Result<A, E>
    fn g() -> Result<B, E>
Then you can write

     fn h() -> Result<(A,B), E> {
        let x = f()?;
        let y = g()?;
        Ok((x, y))
     }
rather than having to do something like

    fn h() -> Result<(A,B), E> {
       match f() {
           Ok(x)  => {
             match g() {
               Ok(y)  => Ok((x,y)),
               Err(e) => Err(e)
             } 
           },
           Err(e) => Err(e),
       } 
     }
(written from memory, please excuse syntax errors)

What's new is that this also works with Option<A> now.

parent lower 9 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton