Skip to content

Instantly share code, notes, and snippets.

@gfldex
Created April 17, 2024 07:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gfldex/1a292b3d6b7fca0d667394f80c81692c to your computer and use it in GitHub Desktop.
Save gfldex/1a292b3d6b7fca0d667394f80c81692c to your computer and use it in GitHub Desktop.
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