Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
make it clear that flat doesn't recurse and show how to do that
  • Loading branch information
gfldex committed Jul 23, 2016
1 parent fc6c2d5 commit b1e3270
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions doc/Type/Any.pod6
Expand Up @@ -195,6 +195,21 @@ 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
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␤»
=head2 method eager
Interprets the invocant as a list, evaluates it eagerly, and returns that
Expand Down

0 comments on commit b1e3270

Please sign in to comment.