Skip to content

Implement set.update method#573

Merged
adonovan merged 4 commits intogoogle:masterfrom
andponlin-canva:add-set-update
Jan 27, 2025
Merged

Implement set.update method#573
adonovan merged 4 commits intogoogle:masterfrom
andponlin-canva:add-set-update

Conversation

@andponlin-canva
Copy link
Contributor

The method update on the type set is available in the Bazel implementation of Starlark, but unfortunately not this Go implementation. This PR will augment the set implementation to also support the update method.

The `update` method on the `set` is defined
in the Starlark specification [1] but is not
present in the starlark-go implementation.
This change introduces this functionality.

[1] https://github.com/bazelbuild/starlark/blob/master/spec.md#setupdate
Copy link
Collaborator

@adonovan adonovan left a comment

Choose a reason for hiding this comment

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

Thanks for this fix!

Copy link
Collaborator

@adonovan adonovan left a comment

Choose a reason for hiding this comment

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

Thanks again.

switch v := arg.(type) {
receiverSet := b.Receiver().(*Set)

// factored out into a function so that the `defer` is scoped to this iterable
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good point; but the comment isn't necessary as the code speaks for itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The fact that the defer is in the function is obvious but the rationale is probably not so obvious.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's fairly common to call a function literal to reduce the scope of a defer.

@adonovan adonovan merged commit 2fb1215 into google:master Jan 27, 2025
13 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