6.47 Multiple Values
If only one v is provided, the result is the same as just v. Any other number of values must be received by a context that is expecting multiple values, such as with a values binding pattern.
> x+y
3
values(1, 2)
> x+y
3
reducer | |||||||||
values(id maybe_annot init, ...) | |||||||||
| |||||||||
| |||||||||
| |||||||||
|
function | ||
|
Use call_with_values to dispatch on the number of values that are produced by an expression. The match form cannot make that distinction, because it always expects a single result value from its initial subexpression.
match n
| 0: values()
| 1: "apple"
| 2: values("apple", "banana")
| show(): println("nothing")
| show(s): println(s)
> call_with_values(fun (): get_fruit(0), show)
nothing
> call_with_values(fun (): get_fruit(1), show)
apple
> call_with_values(fun (): get_fruit(2), show)
apple and banana
> call_with_values(fun (): get_fruit(3), show)
apple and 3 bananas