Match¶
| Name | Mandatory | Description | Default | Type |
|---|---|---|---|---|
⬅️ Input |
The value that's compared with the declared cases. | Any |
||
Output ➡️ |
Same value as input if :Passthrough is true else the output of the matched case's shard if :Passthrough is false. |
Any |
||
Cases |
No | Values to match against the input. A none case will match anything. |
[] |
[Any] |
Passthrough |
No | Parameter to control the shard's output. true allows the Match shard's input itself to appear as its output; false allows the matched shard's output to appear as Match shard's output. |
true |
Bool |
Compares the input with the declared cases EXACT values (use Cond for more complex matching logic) in order of the declaration and activates the shard of the first matched case.
Details¶
Match compares its input with every case declared via the Cases parameter (in the order of their declaration) till a match is found.
Once a match is found the shard of that matched case is activated/executed and Match execution stops. All subsequent cases (even matching ones) are ignored.
A none case matches anything, so it's a good practice to declare a none case at the end of Cases to execute some default logic if no valid matches exist for a given input. If you do not have a none case, then a non-matching input to Match will fail the shard.
A note on Passthrough¶
The Passthrough parameter can control the final output of the shard it applies to.
Setting this parameter to true allows the original input of a shard to pass through as its output as well. If this parameter is set to false, passthrough is suppressed and then the output of the shard is the actual computed value coming out from the shard execution. When set to false, the output of all cases needs to be of the same type.
Examples¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
[info] [sample-wire] Matched nil
[info] [sample-wire] Matched nil