method tree
Documentation for method tree
assembled from the following types:
class Any
From Any
(Any) method tree
Defined as:
multi method tree(Any:)multi method tree(Any:)multi method tree(Any: Whatever )multi method tree(Any: Int(Cool) )multi method tree(Any: @ [, *])multi 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 its invocant otherwise.
say Any.tree; # OUTPUT: «Any»
.tree
has different prototypes for Iterable elements.
my = ( 'A', ('B','C', ('E','F','G')));say .tree(1).flat.elems; # OUTPUT: «6»say .tree(2).flat.elems; # OUTPUT: «2»say .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.