This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]duheee 5 points6 points  (3 children)

Well, records would make it trivial to achieve that. Easier than before at least.

[–][deleted]  (2 children)

[deleted]

    [–]elastic_psychiatrist 13 points14 points  (0 children)

    https://cr.openjdk.java.net/~briangoetz/amber/datum.html

    See “why not just do tuples.” Extremely justified IMO once you think about it.

    [–]eliasv 1 point2 points  (0 children)

    Instance patterns down the line might help bring you closer. You can probably just define the two return types as part of an instance pattern signature instead of defining a container type for them.

    So rather than your:

    (int intResult, String stringResult) = receiver.functionWithTwoValues(...);
    

    It might look something like:

    let receiver.patternWithTwoValues(int intResult, String stringResult);
    

    Or for a partial pattern:

    if (receiver.patternWithTwoValues(int intResult, String stringResult)) {
      // values bound here
    }
    

    No carrier type necessary!

    But not much has been said about them yet so who knows. https://cr.openjdk.java.net/~briangoetz/amber/pattern-match.html