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 container.FilterSlice function #30339

Merged
merged 4 commits into from Apr 9, 2024
Merged

Add container.FilterSlice function #30339

merged 4 commits into from Apr 9, 2024

Conversation

oliverpool
Copy link
Contributor


Many places have the following logic:

func (jobs ActionJobList) GetRunIDs() []int64 {
	ids := make(container.Set[int64], len(jobs))
	for _, j := range jobs {
		if j.RunID == 0 {
			continue
		}
		ids.Add(j.RunID)
	}
	return ids.Values()
}

this introduces a container.FilterMapUnique function, which reduces the code above to:

func (jobs ActionJobList) GetRunIDs() []int64 {
	return container.FilterMapUnique(jobs, func(j *ActionRunJob) (int64, bool) {
		return j.RunID, j.RunID != 0
	})
}

(I noticed this pattern while looking at #29515)

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 8, 2024
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 8, 2024
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label Apr 8, 2024
modules/container/filter.go Outdated Show resolved Hide resolved
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Apr 8, 2024
@oliverpool oliverpool changed the title Add container.FilterMapUnique function Add container.FilterSlice function Apr 9, 2024
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Apr 9, 2024
@lunny lunny added type/refactoring Existing code has been cleaned up. There should be no new functionality. reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. labels Apr 9, 2024
@lunny lunny added this to the 1.23.0 milestone Apr 9, 2024
@lunny lunny merged commit d547b53 into go-gitea:main Apr 9, 2024
26 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Apr 9, 2024
@oliverpool oliverpool deleted the tmap branch April 9, 2024 12:29
zjjhot added a commit to zjjhot/gitea that referenced this pull request Apr 10, 2024
* giteaofficial/main:
  Fix line height on inline code preview (go-gitea#30372)
  Refactor more filterslice (go-gitea#30370)
  Fix ambiguous id when fetch Actions tasks (go-gitea#30382)
  Fix floated list items (go-gitea#30377)
  Fix actions design about default actions download url (go-gitea#30360)
  Add container.FilterSlice function (go-gitea#30339)
  Fix label-list rendering in timeline, decrease gap (go-gitea#30342)
  Performance optimization for git push (go-gitea#30104)
  Reduce checkbox size to 15px (go-gitea#30346)
@wxiaoguang wxiaoguang modified the milestones: 1.23.0, 1.22.0 Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/go Pull requests that update Go code size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/refactoring Existing code has been cleaned up. There should be no new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants