Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env raku
- use v6.d;
- subset CustomKey of List where .elems == 2 && .all ~~ UInt:D;
- subset CustomValue of List where * ~~ (
- :foo(UInt:D)
- :bar(Str:D)
- ).sort;
- class CustomHash does Associative[CustomValue:D, CustomKey:D] {
- has CustomValue:D %!data{Str:D};
- method AT-KEY(CustomKey:D \k --> CustomValue) { %!data{k.Str} }
- method EXISTS-KEY(CustomKey:D \k --> Bool:D) { %!data{k.Str}:exists }
- method ASSIGN-KEY(CustomKey:D \k, CustomValue:D \v) { %!data{k.Str} = v }
- }
- my CustomHash:D \a = CustomHash.new;
- a{$(12,34)} = (foo => 123, bar => 'hi').sort.List;
- a{$(12,34)}.raku.say; # $(:bar("hi"), :foo(123))
- a{$(12,35)}.defined.say; # False
- a{$(13,34)}.defined.say; # False
Advertisement
Add Comment
Please, Sign In to add comment