Part of the vision of pattern matching is aggregation and destructuring [1]. This is just exploratory but may be what you're thinking about?
[1] https://github.com/openjdk/amber-docs/blob/master/site/desig...
[1] https://github.com/openjdk/amber-docs/blob/master/site/desig...
At first glance, it looks like this (sure, more powerful) pattern matching system is not going to satisfy my desire for a compact syntax that lets me do the equivalent of this typescript:
const [foo, bar] = getMeTwoThings();With the pattern matching the best you are going to get is nasty boiler plate like
var returnedTuple = getMeTwoThings();
if (returnedTuple instanceof MyTupleType(Foo foo, Bar bar)) {
// Do something with foo and bar
} else {
// Not reachable unless refactoring, etc. So panic here.
}
That else clause is so terrible you'd probably just rather use the getters from the type. var MyTupleType(Foo foo, Bar bar) = getMeTwoThings();
which IIRC may be even simplified to var MyTupleType(foo, bar) = getMeTwoThings();
EDIT: found it https://mail.openjdk.java.net/pipermail/amber-spec-experts/2... let Point(var x, var y) = aPointWhat are the benefits of having a multiple return type function?
I just assume that one can use an object if this is needed throughout the whole code..
Or maybe create an arraylist if possible and return that?
In go you can do this:
function (x, y int) (sum, prod int) { return x+y, x*y }
It makes a big difference when one is using the same input to generate multiple related outputs.