Skip to content

[Request] Overlapping match statements #2003

@Nokel81

Description

@Nokel81

The ability to specify in a match statement that given some results the execute in top down order of all the statements that match.

Example:
Current:

match cmp.compare(&array[left], &array[right]) {
    Less => {
        merged.push(array[left]);
        left += 1;
    },
    Equal => {
        merged.push(array[left]);
        merged.push(array[right]);
        left += 1;
        right += 1;
    },
    Greater => {
        merged.push(array[right]);
        right += 1;
    }
}

my proposal for the new syntax:

match all cmp.compare(&array[left], &array[right]) {
    Less, Equal => {
        merged.push(array[left]);
        left += 1;
    },
    Greater, Equal => {
        merged.push(array[right]);
        right += 1;
    }
}

Basically this would be an extension to the current patterns where a comma signifies an overlapping qualifier meaning that if the value matches the overlap then it executes the code and then continues on searching.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-langRelevant to the language team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions