Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NonEmptyList copy-constructors accept Collection #36

Merged
merged 4 commits into from
Feb 20, 2024

Conversation

runeflobakk
Copy link
Member

Instead of requiring a List, which is unnecessary strict. This aligns with the JDK copy constructors for lists:

Keeping around the constructors accepting Lists, because of backwards compatibility.

Instead of requiring a List, which is unnecessary strict. This aligns
with the JDK copy constructors for lists:

public ArrayList(Collection<? extends E> c)
https://docs.oracle.com/javase/8/docs/api/java/util/ArrayList.html#ArrayList-java.util.Collection-

List.copyOf
https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/List.html#copyOf(java.util.Collection)
Less specific types in method parameters is not binary backwards
compatible :(

The methods can and should be deleted for a new major-release.
* or {@link Optional#empty()} if the given collection is empty
*/
static <E> Optional<NonEmptyList<E>> copyOf(Collection<E> collection) {
return of(new ArrayList<>(collection));
Copy link
Member Author

@runeflobakk runeflobakk Feb 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using copy constructor of ArrayList from the JDK instead of the oh-so-fancy firstOf(list).map(...) previously used for copyOf(List).

@runeflobakk runeflobakk merged commit 65db4df into main Feb 20, 2024
5 checks passed
@runeflobakk runeflobakk deleted the nonemptylist-copyof-loosen-typing branch February 20, 2024 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants