Patterns are a convenient, concise syntax for receiving some incoming data and doing some common things with it. Keep reading to see how.
We use patterns to make new locals.
Everything to the left of an = is a pattern.
The pattern on the left receives incoming data from the expression on the right.
To the left of this = is a pattern that stores the incoming data into a local named a.
If we're receiving a struct, we can destructure the incoming struct and put its members into locals.
In this example, we're taking the parts of the Vec3 and assigning them into locals a, b, c.
Every parameter is a pattern.
Here, we're using destructuring for this function's parameters.
These are planned features for Vale. See the roadmap for plans!
We can use a pattern to check if the incoming data is a certain value.
Here, we're using a match statement to check what the user entered.
In patterns, _ matches any incoming data and discards it.
We can even check an incoming interface, to see what substruct it is.
We can even destructure it at the same time!