operator ~ method

  1. @Deprecated('Use `Option.call()` as `value()` to unwrap `Option` type values instead.')
T operator ~()

Deprecated: Use Option.call() as value() to easily unwrap Option type values instead.

Shortcut to call Option.unwrap().

Warning: This is an unsafe operation. An OptionError will be thrown if this operator is used on a None value. You can take advantage of this safely via catchOption/catchOptionAsync.

var foo = Some(1);
var bar = Some(2);

print(~foo + ~bar); // prints: 3

Note: if you need to access fields or methods on the held value when using ~, you'll need to use parentheses like so:

var opt = Some(1);

print((~opt).toString());

Additionally, If you need to perform a bitwise NOT on the held value of an Option, you have a few choices:

var opt = Some(1);

print(~(~opt)); // prints: -2
print(~~opt); // prints: -2
print(~opt.unwrap()); // prints: -2;

See also: Rust: Option::unwrap()

Implementation

@Deprecated('Use `Option.call()` as `value()` to unwrap `Option` type values instead.')
T operator ~() => unwrap();