Allow Enumerable#flatten to take a block
I see a new method
#flat_map has been added to Enumerable. Yet passing a block to #flatten has no use. That seems a waste, as it adds yet another method to remember when one we already know can do the job and makes sense.
Updated by trans (Thomas Sawyer) over 8 years ago
I think #flat_map makes more sense than #flatten accepting a block. It's unclear to me what #flatten would do with the block based on the name alone.
I never felt that this is a good kind of argument per-se. For instance, at first I did not understood the use of the term #map or what it would do with a block on the name alone. The term #collect made much more sense to me, but in time I became accustomed to #map, and being shorter that's all I use now.
So for #flatten, seeing that we all already use it, I'm not sure how it could be very unclear. In other words, what else could #flatten do with a block? Seems to me there are only too general choices (for any such method really), either it collects or it conditions. Do you think the block would make more sense as a condition of when to flatten and when to not? Maybe that would be better, and I would be willing to support that instead.
I just don't like to see new methods invented if another method could serve the purpose, so I think it's good to be sure about it.
Updated by mame (Yusuke Endoh) over 8 years ago
- Status changed from Open to Assigned
- Assignee set to matz (Yukihiro Matsumoto)
#flatten is recursive by default. #flat_map is not.
So I don't think it is a good idea to extend #flatten.
Anyway, #flat_map is already included in 1.9.
We no longer need to extend #flatten, I think.
Yusuke Endoh firstname.lastname@example.org