-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Allow passing a function to join #30328
Conversation
Patterns such as `join(map(uppercase, xs))` can now be written more succinctly and efficiently as `join(uppercase, xs)`.
Alternatively: Or as implementation: |
Yeah, using generators here seems more composable and general than adding function arguments to everything? |
I wholeheartedly disagree. What's the point of first-class functions and other features from functional programming if you don't get to use them? This isn't Python; littering everything with generators does not improve efficiency or readability. |
FWIW it is not that obvious what the function argument does, I thought it would decide how to join, with |
It seems fairly obvious and consistent to me, since other places we allow function arguments, they (almost?) always mean "map this function across the input during the reduction operation." |
The other ones are generally reducers of some kind like |
I would argue that it does, as it's equivalent to |
I've noticed a growing number of these types of "map as you go" methods for functions. I'd raise a couple points:
Such a discussion might deserve it's own issue, I suppose. (Perhaps this has already been discussed somewhere already?)
First-class functions allow you to build lazily mapped containers efficiently, which lets us seperate the concerns of the mapping and the joining to two different operations. This seperation of concerns feels like better software engineering to me, rather than having to add the "lazy mapping" comcept to each and every function in |
I don't get why people seem to be taking this addition to that extreme. There is a fairly clear set of functions that should support this, namely reduction operations, which hardly constitutes "every function in Base." |
Patterns such as
join(map(uppercase, xs))
can now be written more succinctly and efficiently asjoin(uppercase, xs)
. I've found myself wanting this often lately.I've set the
!!! compat
notice to 1.1, but I can change it to 1.2 or whatever as needed.