vavr-io / vavr

vʌvr (formerly called Javaslang) is a non-commercial, non-profit object-functional library that runs with Java 8+. It aims to reduce the lines of code and increase code quality.
https://vavr.io
Other
5.74k stars 637 forks source link

Array.of() vs. Array.allOf() #2251

Closed cal101 closed 4 years ago

cal101 commented 6 years ago

Hi!

We are using guava for some time now for immutable collections. We are revisiting decisions from time to time and I am looking at vavr again after the name change. For example guava ImmutableList has companion methods of of() and 'copyOf()', too, like for example vavr Array has of and ofAll. When test converting some code from Java arrays and ImmutableList to vavr Array I noticed that Array.of(<some-java-array>) has to be used compared to ImmutableList.copyOf(<some-java-array>). That is especially interesting for me because at some time in the past guava switched from ImmutableList.of(<some-java-array>) to ImmutableList.copyOf(<some-java-array>). It took a little bit of work to change that in our code base but I think they are right on this. If you want to create a collection from some other collection that should include from arrays in my opinion. And XXX.of() should be kept for enumerated single values. That '...' is converted to an array is just an implementation detail and I suggest following the guava and the JDK (9? 10?) example and

  1. use "allOf()" for Arrays
  2. add overloaded versions of 'of()' to avoid creation of intermediate var args array for the majority of cases.

Thanks for reading so far ;-)

danieldietrich commented 6 years ago

This makes sense. I agree with 1. and 2. But we should use ofAll instead of allOf to be consistent with our existing naming scheme. I like 'ofAll' because autocompletion and API are side-by-side to 'of' (=> better UX).

danieldietrich commented 4 years ago

On help let's discuss it first.

pivovarit commented 4 years ago

So, as I understood there are a few things to take care of:

Is there anything else you have in mind?

danieldietrich commented 4 years ago

@pivovarit I've thought about this topic. I prefer to align to standard Java API instead of a 3rd party API like Guava.

In Java, it is common practice to have of(T) and of(T...), e.g. see Java's Stream API.

If no one complains, I will close this issue.


See also

pivovarit commented 4 years ago

If no one complains, I will close this issue.

Regardless of the fact if there's something to be done here, it feels like it's a part of https://github.com/vavr-io/vavr/issues/2125