method tree

Documentation for method tree assembled from the following types:

class Any

From Any

(Any) method tree

Defined As:

method tree(--> Any)

Returns the class if it's undefined or if it's not iterable, returns the result of applying the tree method to the elements if it's Iterable.

say Any.tree# OUTPUT: «Any␤» 

.tree has different prototypes for Iterable elements.

my @floors = ( 'A', ('B','C', ('E','F','G')));
say @floors.tree(1).flat.elems# OUTPUT: «6␤» 
say @floors.tree(2).flat.elems# OUTPUT: «2␤» 
say @floors.tree*.join("-"), *.join(""), *.join("|" )); # OUTPUT: «A-B—C—E|F|G␤» 

With a number, it iteratively applies tree to every element in the lower level; the first instance will apply .tree(0) to every element in the array, and likewise for the next example.

The second prototype applies the Whatever code passed as arguments to every level in turn; the first argument will go to level 1 and so on. tree can, thus, be a great way to process complex all levels of complex, multi-level, data structures.