dfinity / motoko

Simple high-level language for writing Internet Computer canisters

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request: Super-set pattern matching

Gekctek opened this issue · comments

public type V1 = {
    #a;
    #b;
    #c;
};

public type V2 = {
    #b;
    #c;
};

func foo(variant : V1) {
    switch(variant){
        case (#a) {
            ...
        }
        case (superSet) bar(superSet);
    }
}

func bar(varaint : V2) {
    ...
}

This comes up much more than I expect, where I have a cases, and just some of them i want to handle, then propagate or call a method with a smaller set. This can be done manually or through using variants within variants like

public type V1 = {
  #one: { #a };
  #two: { #b; #c );
  };

So maybe its just a change in my mindset vs a feature requirement, but could be powerful.

That being said, this seems non-trivial of a task and I could see there being weird complexities. So its a low priority

This is a duplicate of #4308. If you agree, please close.