Tree Method - Any, Iterable

What does the tree method do in Perl6?

From Perl6 Documentation

Returns a class if it is undefined, or if it does not repeat, the result of applying the method treeto elements, if it is, is returned Iterable.

However, there is no description of the tree method in the "iterable" documentation.

I tried:

my $a = 1..4;
say $a.tree;

And received:

$ perl6 test.pl6
(1 2 3 4)

Unlike attempts:

my $a = 1..4;
say $a;

And having received:

$ perl6 test.pl6
1..4

But I'm not quite sure what the difference is or what it means.

In the type list on the Perl6 document website, there does not seem to be a separate tree type.

+4
source share
1 answer
$ perl6 -e 'say (1, (^5), ((4,5),), 6).tree(*.self, *.reverse)'
(1 (4 3 2 1 0) ((4 5)) 6)

$ perl6 -e 'say (1, (^5), ((4,5),), 6).tree(*.self, *.reverse, *.sum)'
(1 (4 3 2 1 0) (9) 6)

, 3- .sum, 2- , 1- , .

, perl6 roast https://github.com/perl6/roast

https://github.com/perl6/roast/blob/ad9f949e2b479b5800c3e6315f979ded595a09fd/S02-lists/tree.t

+4

Source: https://habr.com/ru/post/1694746/


All Articles