On Sun, Jun 9, 2024 at 10:29 PM Gary Gregory <garydgreg...@gmail.com> wrote: > > Please do ;-)
Groovy provides Tuple0 through Tuple16 all of which extend Tuple which implements List. Tuple2 acts like Pair (more accurately ImmutablePair). Tuple2 implements Serializable and Comparable (like Pair) but not (currently) Map.Entry. The following are more or less equivalent: Pair<String, String> pair1 = Pair.of("foo", "bar"); // commons-lang Tuple2<String, String> pair2 = Tuple.tuple("foo", "bar"); // groovy-core Tuple<String> pair3 = new Tuple<>("foo", "bar"); // groovy-core Tuple3 acts like Triple (actually ImmutableTriple). Both implementing Serializable and Comparable. Examples: Triple<String, String, String> triple1 = Triple.of("foo", "bar", "baz"); // commons-lang Tuple3<String, String, String> triple2 = Tuple.tuple("foo", "bar", "baz"); // groovy-core The static factory method is "tuple" instead of "of". The accessors are getV1(), getV2() etc. instead of getLeft(), getRight(). The classes are all written in Java and make no calls back into the Groovy runtime - folks could extract the classes if they really wanted. The class hierarchy might seem a little strange for Java folks, e.g. For Tuple<String, Integer>, calling parent methods from Tuple is actually typed as (Tuple<Object>), e.g. get, subList, subTuple will return results of type Object, List<Object>, Tuple<Object> respectively. This would typically be transparent when used from Groovy in dynamic mode but you might have to be aware of that when using static Groovy or Java. The fact that the classes extend List, means that 100+ Groovy List extension methods work on Tuples, e.g: System.out.println(DefaultGroovyMethods.intersect((Iterable<String>)pair2, triple2)); // Java assert pair2.intersect(triple2) == pair2 // Groovy In Groovy, Tuples pop up in various places, e.g. there is special support in Groovy for records (and emulated records) to return typed tuples, e.g. for JDK8+: @RecordOptions(components=true) record Person(String name, Integer age) { } var mary = new Person("Mary", 25) Tuple2<String, Integer> nameAndAge = mary.components() HTH, Paul. > Gary > > On Sun, Jun 9, 2024, 7:38 AM Paul King <paul.king.as...@gmail.com> wrote: > > > May or may not interest you but the Apache Groovy project has Tuple0 > > through to Tuple16. They are especially useful from the Groovy > > programming language but are also useful from Java. I can elaborate if > > it's of interest. > > > > Cheers, Paul. > > > > On Fri, Jun 7, 2024 at 11:41 PM Gary Gregory <garydgreg...@gmail.com> > > wrote: > > > > > > Hello Michał. > > > > > > Nope ;-) > > > > > > Though, PRs are welcome! However, it might be best to detail your > > > proposal here before spending time on something that might not attract > > > interest. > > > > > > Gary > > > > > > On Fri, Jun 7, 2024 at 9:28 AM Michal Brach > > > <mbr...@softsystem.pl.invalid> wrote: > > > > > > > > Hi, > > > > > > > > do you have any plans to provide new items in > > org.apache.commons.lang3.tuple e.g. Quartet > > > > > > > > Thanks in advance. > > > > > > > > > > > > > > > > > > > > Michał Brach > > > > SoftSystem | Gene Dev 2 > > > > Ext 7317 > > > > ________________________________ > > > > > > > > Ta wiadomość pocztowa i wszelkie załączone do niej pliki są poufne i > > podlegają ochronie prawnej. > > > > Jeśli nie jesteś jej prawidłowym adresatem, jakiekolwiek jej > > ujawnienie, reprodukcja, dystrybucja lub inne rozpowszechnienie, są ściśle > > zabronione. > > > > Jeśli otrzymał Pan/Pani niniejszy przekaz wskutek błędu, proszę o > > niezwłocznie powiadomienie nadawcy i usunięcie otrzymanych informacji. > > > > > > > > This message is confidential and may also be legally privileged. > > > > You should not copy or forward this message or disclose its contents > > to any person. > > > > If you are not the intended recipient, please notify the sender by > > return email and then delete this message from your system. > > > > > > --------------------------------------------------------------------- > > > To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org > > > For additional commands, e-mail: dev-h...@commons.apache.org > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org > > For additional commands, e-mail: dev-h...@commons.apache.org > > > > <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> Virus-free.www.avast.com <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org