Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Backpassing

Function based

Monad based

Uses With Containers

func maybe_sum(x: Option<U32>, y: Option<U32>) -> Option<U32> {
    x.flat_map do(i) {
        y.flat_map do(j) {
            Some(i + j)
        }
    }
}
func maybe_sum(x: Option<U32>, y: Option<U32>) -> Option<U32> {
    let i = x.flat_map?;
    let j = y.flat_map?;

    Some(i + j)
}

Backpassing match Special Form

match(foo) {
  True?,
  False -> print("nope"),
};

print("yep");

Expression returns a tuple.

With values

match(foo) {
  Pass(value)?,
  Fail(error) -> print("oh no: \(error)"),
};

print("yippee: \(value)");