Skip to content

Instantly share code, notes, and snippets.

@grondilu
Created August 24, 2013 00:38
Show Gist options
  • Save grondilu/6325278 to your computer and use it in GitHub Desktop.
Save grondilu/6325278 to your computer and use it in GitHub Desktop.
role BinaryTree[::T] {
has T $!value;
has BinaryTree[T] ($.left, $.right);
method replace-all(T $value) {
$!value = $value;
$.left.?replace-all($value);
$.right.?replace-all($value);
}
}
class IntTree does BinaryTree[Int] { }
my IntTree $it .= new(value => 1,
left => IntTree.new(value => 2),
right => IntTree.new(value => 3));
$it.replace-all(42);
say $it.perl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment