Skip to content

Commit 39f4221

Browse files
authored
Don't reinvent the wheel in .flat example
1 parent b9edd20 commit 39f4221

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

doc/Type/Any.pod6

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,20 +181,15 @@ all your RAM in the process.
181181
say ((1, 2), (3)).elems; # 2
182182
say ((1, 2), (3)).flat.elems; # 3
183183
184-
Please not that C<flat> is not recursing into sub lists. You have to recurse by
184+
Please not that C<flat> does not recurse into sub lists. You have to recurse by
185185
hand or reconsider your data structures. A single level of nesting can often be
186186
handled with L<destructuring|/type/Signature#Destructuring_Parameters> in
187187
signatures. For deeper structures you may consider
188188
L<gather/take|/syntax/gather take> to create a lazy list.
189189
190190
my @a = [[1,2,3],[[4,5],6,7]];
191-
sub deepflat(@a){
192-
gather for @a {
193-
take ($_ ~~ Iterable ?? deepflat($_).Slip !! $_)
194-
}
195-
};
196-
dd deepflat(@a);
197-
# OUTPUT«(1, 2, 3, 4, 5, 6, 7).Seq␤»
191+
say gather deepmap *.take, @a;
192+
# (1 2 3 4 5 6 7)
198193
199194
=head2 method eager
200195

0 commit comments

Comments
 (0)