dfinity / motoko

Simple high-level language for writing Internet Computer canisters

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: If with pattern match

Gekctek opened this issue · 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
}