-
-
Save lucasbuchala/9340fcfee0d8671d8572b002d7418172 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 Duo::Role[::KeyType, ::ValueType] { | |
has KeyType $.key is rw = KeyType; | |
has ValueType $.value is rw = ValueType; | |
} | |
class Duo {...} # stub to be used by Duo::Base below | |
class Duo::Base { | |
method set(\list) { ($.key, $.value) = list; self } | |
method get() { $.key, $.value } | |
} | |
class AnyDuo is Duo::Base does Duo::Role[Any, Any] { | |
} | |
class Duo { | |
method ^parameterize(\type, ::KeyType, ::ValueType) { | |
my \C = Metamodel::ClassHOW.new_type: :name("Duo[{ KeyType.^name },{ ValueType.^name }]"); | |
C.^add_parent: Duo::Base; | |
C.^add_role: Duo::Role[KeyType, ValueType]; | |
C.^compose; | |
C; | |
} | |
} | |
dd AnyDuo.new(key=>1, value=>2); | |
dd Duo[Any, Any].new(key=>1, value=>2); | |
dd Duo[Int, Str].new(key=>1, value=>2); | |
dd Duo[Cool, Cool].new(key=>1, value=>2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment