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
Sub descend and method Any::descend return a recursively flat Seq #834
Conversation
anything that implements deepmap.
What's the usecase for this method/sub? I rather not add more core methods and subs that save only half a dozen of keystrokes, unless they are very commonly used. Especially since we already have |
see discussion https://irclog.perlgeek.de/perl6/2016-07-28#i_12929268 flat simply does not work for most use cases. It doesn't work for arrays nor does it recurse array or not. We have deepmap and map to recurse or not but there is no recursive iterator. descend fills that gap. |
As I've mentioned on IRC, I feel like maybe Maybe Lastly, if we do go with adding a new routine, I think the name is not ideal. Currently it implies going into the guts of the thing and doing something while in there, whereas it just flattens the thing (which is what drove my feeling that we should be improving My choice would be to make |
flat makes a distinction between Array and List/Seq.
Just changing the behaviour of flat will have massive fallout in the ecosystem. Adding a named to flat should not. |
How did you arrive at that estimate? Looking at May 3rd ecosystem snapshot, the about 380 instances of I'm hardpressed to find code that relies on |
I'm curious what TimToady has to say, in that this is not the first time it has come up. Thus, there must have been a reason provided for the current behavior. I'd like to interrogate that reasoning while discussing this change. |
FYI, I've written up a summary of the current options for "deep" ( TL;DR:
I've used it in code golf, but probably not in "real" code. (I could be wrong, of course - it might be insightful to change the behavior in a Rakudo branch and see what breaks.)
Before the GLR, lots of things (e.g. Therefore, people needed a way to prevent sub-lists from being flattened in case they wanted to work with nested data-structures. The GLR changed a lot, and now built-ins prefer to keep nested lists as they are, and instead let you manually flatten them when when you do want it - either from the outside ( However, the release of 6.c happened shortly after the GLR was finished in order to make the Christmas deadline, and I think not all parts of the language were thoroughly reviewed to re-examine them in light of the GLR. If there had been more time and willingness to reexamined/change things after the GLR, my personal guess is that the whole concept of It's not just class Person { has $.name; has @.hobbies; }
my %a = name => "Ben", hobbies => <reading skating>;
say Person.new(|%a);
# The @.hobbies attribute now doesn't hold the two elements "reading"
# and "skating" as the user probably expected, but rather the single
# element $("reading", "skating") In practice, scalarization is still sometimes used to force an array to be treated as a single item, but I can't think of any case where it is necessary, because there are alternative ways to achieve the same thing. For example: say $@array X 1..10; # (@array, 1), (@array, 2), ... (@array, 10)
say (@array,) X 1..10; # Scalarization-free alternative So... that's where things are at. Whether it is possible to change any of this (either specifically for |
Note that it ruins Maps:
|
Thank you for your effort, however I'm going to reject this. It adds another method to practically all Perl 6 classes that saves only three words of typing and doesn't work with Hashes and Maps in a desirable way. |
of anything that implements deepmap.