# Pastebin uYLW4MdL class OptionalObj {...} class Optional { has $.type; method __instanciate(Mu:U $type) { self.bless(:$type) } method new(*%h, *@a){ OptionalObj.new(:instance($.type.new(|%h, |@a))) }; method FALLBACK(Str $meth, *%h, *@a) { $.type.$meth(|%h, |@a) } method null() { OptionalObj.new(:instance(Nil)) } } class OptionalObj { has $.instance; method FALLBACK(Str $meth, *%h, *@a) { self but False } method say(*%h, *@a) { self but False } } multi sub postfix:(Mu:U $type) { Optional.__instanciate($type) } multi sub postfix:(OptionalObj $obj) { $obj.instance || $obj } class Point { has $.x; has $.y; } my $test = Point?.new(:x(42), :y(43)); $test?.x.say; # prints 42 my $test2 = Point?.null; $test2?.x.say; # do not print my Point? $test3; # breaks $test3?.x.say; # ... # ===SORRY!=== # Type 'Point' is not declared # at opt.p6:45 # ------> my Point⏏? $test3; # Malformed my # at opt.p6:45 # ------> my Point⏏? $test3; #