Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Don't reinvent the wheel in .flat example
  • Loading branch information
zoffixznet committed Dec 25, 2016
1 parent b9edd20 commit 39f4221
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions doc/Type/Any.pod6
Expand Up @@ -181,20 +181,15 @@ all your RAM in the process.
say ((1, 2), (3)).elems; # 2
say ((1, 2), (3)).flat.elems; # 3
Please not that C<flat> is not recursing into sub lists. You have to recurse by
Please not that C<flat> does not recurse into sub lists. You have to recurse by
hand or reconsider your data structures. A single level of nesting can often be
handled with L<destructuring|/type/Signature#Destructuring_Parameters> in
signatures. For deeper structures you may consider
L<gather/take|/syntax/gather take> to create a lazy list.
my @a = [[1,2,3],[[4,5],6,7]];
sub deepflat(@a){
gather for @a {
take ($_ ~~ Iterable ?? deepflat($_).Slip !! $_)
}
};
dd deepflat(@a);
# OUTPUT«(1, 2, 3, 4, 5, 6, 7).Seq␤»
say gather deepmap *.take, @a;
# (1 2 3 4 5 6 7)
=head2 method eager
Expand Down

0 comments on commit 39f4221

Please sign in to comment.