Created
April 17, 2024 07:34
-
-
Save gfldex/1a292b3d6b7fca0d667394f80c81692c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my \l = ("Hello", "bye", ("something", ("list", "foo", "boo"), ("mars", "bar"))); | |
sub tree-it($item) { | |
my %h is default(IterationEnd) = $item.pairs; | |
do for 0..* -> $idx { | |
last if %h{$idx}:!exists; | |
my $left = %h{$idx}; | |
my $right = %h{$idx + 1}; | |
dd $right; | |
$left & $right ~~ Str | |
?? |($left, '-') | |
!! ($left ~~ Str && $right ~~ Positional) | |
?? |($left, '|\\') | |
!! $left ~~ Positional | |
?? |(samewith($left), $right ~~ Positional ?? '|' !! Empty) | |
!! $left | |
} | |
} | |
l.&tree-it.say |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment