jOOQ / jOOL

jOOλ - The Missing Parts in Java 8 jOOλ improves the JDK libraries in areas where the Expert Group's focus was elsewhere. It adds tuple support, function support, and a lot of additional functionality around sequential Streams. The JDK 8's main efforts (default methods, lambdas, and the Stream API) were focused around maintaining backwards compatibility and implementing a functional API for parallelism.
http://www.jooq.org/products
Apache License 2.0
2.09k stars 168 forks source link

Treat null as empty array in Seq.of(T[]) #358

Closed pgrisafi closed 5 years ago

pgrisafi commented 5 years ago

Not an issue but an enhancement.

Some time ago I asked for a null-safe Seq constructor for lists, because I work with lots of legacy code and I found myself writing lots of

list == null ? Seq.empty() : Seq.seq(list)

and you were kind enough to implement it

Now I'm back asking for the same thing for arrays, since I'm still handling lots of legacy code and I found myself writing lots of

array == null ? Seq.empty() : Seq.of(array)

Would that be possible?

Expected behavior and actual behavior:

Expected:

Assertions.assertEquals(0, Seq.of((Object[])null).count());

Actual:

throws a java.lang.NullPointerException

P.S.: and what about an overload for Seq.seq(Object[] array) to make the library more consistent? I'm not so sure if this is possible since there is already a

 Optional<? extends T>... optionals)

Versions:

Again, sorry if my English is not clear enough, and thanks for this beautiful lib!

lukaseder commented 5 years ago

Thank you very much for your suggestion. I agree it would be consistent for Seq.of(T[]) to accept null arrays just like empty arrays.

We actually already have seq(T[], int, int). I'm not sure why there's no seq(T[]) overload, so I agree with both of your suggestions.