operator ~ method
Executes the prefixed async function, propagating any unwrapped None() values to the return value of the function.
Shortcut for propagateOptionAsync.
Usage:
// This function will error at runtime if passed a None() value
Future<Option<int>> add(Option<int> a, Option<int> b) async {
return Some(a.unwrap() + b.unwrap());
}
// For safety, it can be rewritten as:
Future<Option<int>> add(Option<int> a, Option<int> b) => ~() async {
return Some(a.unwrap() + b.unwrap());
// You can also use the ~ operator as a shortcut for unwrap():
// return Some(~a + ~b);
};
// Runtime safety achieved from a mere 8 total characters of syntactical overhead!
Implementation
Future<Option<T>> operator ~() => propagateOptionAsync(this);