Giter Club home page Giter Club logo

Comments (3)

abueide avatar abueide commented on July 21, 2024

I just realized how stupid this was remembering that more tuples exist than just Tuple2 and that would break the consistency, sorry!

from jool.

lukaseder avatar lukaseder commented on July 21, 2024

Thanks for your suggestion, @abueide. When I created jOOλ, I had briefly considered what this library did: https://www.javatuples.org

Unit<A> (1 element)
Pair<A,B> (2 elements)
Triplet<A,B,C> (3 elements)
Quartet<A,B,C,D> (4 elements)

Interestingly enough, they named their tuples without indicating the degree as a number, but then still used (zero based, yuck) accessors, like getValue3(), and, probably as a compromise, didn't number their generic type variables, but named them <A, B, C, D>.

This just to show you there isn't really a very satisfying solution that fits everyone. Much better than tuples in general would be records (with named attributes). If Java had anonymous types like C#, then we would hardly use tuples at all, which are impractical, regardless if the value is called v2 or second or whatever. Because a much bettern name for it would be lastName (for example).

As long as type inference works (with lambdas or var), it would actually be possible to write things like:

Stream.of("a", "b")
    .map(s -> new Object() { String name = s; })
    .forEach(o -> System.out.println(o.name));

But we cannot pass around this type between methods, so the utility is almost zero. We did get first class records with Java 14, though, so I have high hopes that the name of tuple attributes will become irrelevant in the future :)

Cheers,
Lukas

from jool.

abueide avatar abueide commented on July 21, 2024

@lukaseder Thanks for sharing your insight on the problem, Java 14's records does look promising.

from jool.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.