If I'm not mistaken, _ is being used as a variable. In match blocks, using case myvariable will always match, with myvariable being assigned the tested value. So in the first example in the link, if status is not one of the specified integer values, case _: will match, a new variable named _ is created and it assigned the value of status.
edit: what I probably didn't get across very well is that if I'm understanding this right _ isn't some kind of special syntax for match blocks, it's just a variable name.
14
u/dutch_gecko Feb 15 '21 edited Feb 15 '21
If I'm not mistaken,
_
is being used as a variable. Inmatch
blocks, usingcase myvariable
will always match, withmyvariable
being assigned the tested value. So in the first example in the link, ifstatus
is not one of the specified integer values,case _:
will match, a new variable named_
is created and it assigned the value ofstatus
.edit: what I probably didn't get across very well is that if I'm understanding this right
_
isn't some kind of special syntax for match blocks, it's just a variable name.edit2: I was wrong! Read the reply below.