-
-
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
Replace flatmap
with a flatten method
#47327
Conversation
Cross ref to a larger PR that also includes these changes #45985 |
Maybe worth noting that no other Iterators functions follow the
|
""" | ||
flatten(f, iterators...) | ||
|
||
Create a lazy flattened mapping. Equivalent to `flatten(Iterators.map(f, iterators...))`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not entirely equivalent to Iterators.map
because the function argument that accepts is untyped whereas the one this accepts is constrained to be a Function
. How bad would it be to do something like
flatten(f, itrs...) = applicable(iterate, f) ? flatten((f, itrs...)) : flatten(map(f, itrs...))
? An approach like this would end up "preferring" iterating in the case that the user passes in some godforsaken object that is both iterable and callable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flatten only accepts a single argument right now, so it would be unambiguous to define flatten(f, itrs...) = flatten(map(f. itrs...))
, but I suppose I wanted nicer error messages when someone calls flatten([1,2,3], [4,5,6])
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh my mistake, I could have sworn there was a vararg method.
Yeah... I'm not a huge fan of adding this method, but I prefer it over the OTOH, the |
I would think that |
I can't understand why opening this new PR. I can understand it's a smaller patch, but we could settle over #45985 the question of whether doing this is desirable. I am opposed to it (both this and #45985). I do see it's a nifty idea, but I'd much rather have separate Triage was fine with having an I made and entire short presentation at JuliaCon basically bacause of this, have you seen it? I try to make the case for flatmap there, among other things. Maybe you could give me some comments about the presentation, and not merely about my short and controversial PRs? https://www.youtube.com/watch?v=2VccdiX-9Tg |
This sounds like a slippery-slope fallacy. Should every single "reduce" style function be able to take a function argument like Same thing for flatmap, it's used (or could be used if it existed) frequently enough to be defined. And let me point it out once again, it's present in the language in the form of the comprehension |
I think The methods we have that add a function as the first argument are kind of ugly honestly, and just there as an occasional convenience. A couple concrete problems: It's awkward for functions like |
Note that flatten takes one argument: #47327 (comment) |
Okay |
From @thchr and @mcabbott's post-merge comments on @nlw0's PR #44792
I would also support removing the function entirely, but triage seems to oppose that