-
Notifications
You must be signed in to change notification settings - Fork 93
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
Select vs Filter #86
Comments
You make a completely valid point. In fact, in early versions of pie it was actually called There is another recent issue #77 where combining Select with a Transform would be really helpful. I think the solution here is a pie.Strings{"hello", "Dylan", "Meeus"}.
Filter(func (value string) (string, bool) {
if (unicode.IsUpper(rune(value[0]))) {
return strings.ToUpper(value), true
}
return "", false
})
// pie.Strings{"DYLAN", "MEEUS"} Currently, this has to be done in two stages: pie.Strings{"hello", "Dylan", "Meeus"}.
Select(func (value string) bool {
return unicode.IsUpper(rune(value[0]))
}).
Transform(strings.ToUpper) As I write it out I realise that may be a bad example because it's kind of looks cleaner like that, but for more complex scenarios it's not as easy to split up. What do you think? In either case, we need to improve the documentation so it's more easily discoverable. |
Hey Elliot, Here's my 2cents, being able to change the representation of Data in a Perhaps this could be combined in something like My idea of these kind of functions is a bit influenced by the (functional) languages I have used of course, where you can easily chain calls without reducing readability. I do think that these type of "higher level" functions should be as self-explanatory as possible. So to summarize, I like the idea but I disgree with the name a bit. :) |
I'm not against the idea of renaming Using a negator function (like In your experience, would you find an opposite to |
Yeah, I figured the negator function would not be as feasible. Of course the user could turn the predicate around inside the But honestly I can't think of another language which includes this - nor can I think of a name that immediatly sounds good to me. Some suggestions off the top of my head:
To just "brainstorm" and throw another idea out there.. this is something which I have seen in another language but I can't remember which one. A method to keep "both" the elements to which the predicate applies and those where it does not. e.g
I can't think of something that keeps the symmetry and sounds natural. (Purely for the symmetry |
I still like the idea of having a negating filter because I have used names.Select(func (value string) bool {
return !actualTest(value)
}) Sometimes my mind goes off on a tangent until I realise that I've forgotten the essence of what I'm trying to answer. Not all things need to be generalised to work. I think the answer is as simple as just having a You have convinced me that it's worth changing these now. If you have no further comments I'm fine with:
Would you like to put in a PR for it? |
Hey Elliot, I think those changes look good :) |
Hey,
This lib looks really neat, thank you & good job! 👍
Just one thing that kind of surprised me. The
Filter
method is calledSelect
here. There are quite a few languages that have the terminology forFilter
. I don't really knowSelect
from other languages, but that might be my ignorance 😄.I believe that a lot of people will ook for a
Filter
method (I tried before finding out it'sSelect
).What do you think of renaming it toFilter
? (It does break the symmetry betweenSelect
andUnselect
. But I also thinkUnselect
is not a common name).For comparison, here is a list of names for the "Filter" function in different languages: https://en.wikipedia.org/wiki/Filter_(higher-order_function).
Only mathematica seems to be using the
Select
terminology.So, in short. I'd say
Select
->Filter
to make it easier for people to find/understand which method they need. What do you think?I'd want to contribute this change. But I first want to know your opinion. Maybe my concern is unfounded 😅 Not to mention this will break some dependencies. Unless we can introduce a synonym and have both Filter/Select. (They can point to the same implementation, so it'd just be kind of like a "typedef").
The text was updated successfully, but these errors were encountered: