-
Notifications
You must be signed in to change notification settings - Fork 23
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
[Feature 🔨]: Add Uniq
and UniqF
functions to generate only unique values
#146
Comments
Thanks for idea! I like the feature but would prefer different names. The functions should be "verbs" because they do something to other iterators - I'd also prefer to avoid abbreviations in function names. Perhaps I'm guessing you'd implement this by storing the elements you find in a map as you go along, so it would be worth mentioning in the docs that order will not be preserved if that's the route you take. |
Makes sense I would prefer For For Like
|
Ah that makes sense, keep the map referenced by the closure! Can you provide an example of how you'd use As for the signatures, it's fine to return |
Ok. makes sense. |
Example: type student struct {
id int
class string
}
membership := []student{
{id: 1, class: "CS"},
{id: 1, class: "Math"},
{id: 100, class: "Math"},
}
uniqueStudents := FilterUniqueBy(slices.Values(membership), func(st student) int {
return st.id
})
fmt.Printf("unique studuents:%+v\n", slices.Collect(uniqueStudents)) Prints unique studuents:[{id:1 class:CS} {id:100 class:Math}]
|
Thanks @apatniv! I'd be happy to accept a pull request for |
Not really. There is workarounds possible but useful to do this in the library.
Add
Uniq
andUniqF
functions to generate only unique valuesSignatures of the function:
No.
Yes
The text was updated successfully, but these errors were encountered: