Skip to content

Instantly share code, notes, and snippets.

@masak
Created April 18, 2010 11:53
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 masak/370183 to your computer and use it in GitHub Desktop.
Save masak/370183 to your computer and use it in GitHub Desktop.
class Tree {
has $.node;
has @.children;
method new($node, *@children) { self.bless(*, :$node, :@children) }
method Str {
@.children ?? "$.node: [@.children.join(", ")]" !! $.node.Str
}
}
multi map(&c, Tree $t) {
Tree.new(c($t.node), map { map(&c, $_) }, $t.children)
}
my $t = Tree.new("H2O", Tree.new("H"), Tree.new("O"), Tree.new("O"));
say $t;
say map { .lc }, $t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment