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

Add ListBuilder.of and SetBuilder.of contructors #298

Merged
merged 3 commits into from
Sep 12, 2024

Conversation

iinozemtsev
Copy link
Contributor

Similar to BuiltList.of, they expect a typed iterable.

Similar to `BuiltList.of`, they expect a typed iterable.
Copy link
Contributor

@davidmorgan davidmorgan left a comment

Choose a reason for hiding this comment

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

Thanks!

One suggestion for the implementation :)

I think the toBuilder methods on BuiltList and BuiltSet should probably be updated to use this instead of the other constructor.

Re: testing, a simple call of the new constructor with [1, 2, 3] and check that those values end up in the builder seems sufficient for correctness :)

It would also be good to have a test like the existing "converts to BuiltList without copying" showing that the constructor does not immediately copy a BuiltList. There should have been such a test for the old constructor already ... but if it's no longer used in toBuilder then that's less important :)

Please also add to CHANGELOG.md.

@@ -15,6 +15,9 @@ class ListBuilder<E> {
late List<E> _list;
_BuiltList<E>? _listOwner;

/// Instantiates with elements from an [Iterable<E>].
factory ListBuilder.of(Iterable<E> elements) => ListBuilder<E>(elements);
Copy link
Contributor

Choose a reason for hiding this comment

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

This ends up calling replace which doesn't benefit from the collection type being known, how about adding a _replaceOf method which uses List.of instead of List.from, then calling that here.

Private because the end goal is that "replace" turns into "replaceOf", but we can worry about that later :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Done

@davidmorgan davidmorgan merged commit 560883b into google:master Sep 12, 2024
2 checks passed
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