Created
January 5, 2014 05:18
-
-
Save TimToady/8264706 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
role BinaryTree[::T] { | |
has T $.value; | |
has BinaryTree[T] $.left; | |
has BinaryTree[T] $.right; | |
method replace-all(T $value) { | |
$!value = $value; | |
$!left.replace-all($value) if $!left.defined; | |
$!right.replace-all($value) if $!right.defined; | |
} | |
} | |
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