Backpassing
Function based
- Gleam’s
useexpressions - Koka’s
withstatement - Roc’s “backpassing” (which unfortunately appears to be a removed feature)
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)");