motoko icon indicating copy to clipboard operation
motoko copied to clipboard

Feature Request: If with pattern match

Open Gekctek opened this issue 2 years ago • 0 comments

Current capabilities for pattern matching usage where i want to do something if the thing matches and skip if it doesnt. This would be code sugar because a switch statement works just fine, but is clunky and makes reading the code hard for such a simple task.

let value : ?MyType = ...;
switch (value) {
  case (null) { // skip };
  case (?v) { // use v };
};
// rest of code

The let-else wont work because I want to just skip it if is null, not end execution Something like this:

if (value is ?v) {
  // Use v
}

Gekctek avatar Jan 08 '24 21:01 Gekctek