# Pastebin fb9aqpiE class Logic::Ternary does Enumeration { my %enumerations = False => -1, Unknown => 0, True => +1, ; my %anti = %enumerations.antipairs; method new(Str:D $val where .one) { self.bless: key => $val, value => %enumerations{$val} } method ^enum_from_value($, $value) { my $key = do given $value { when $_ =:= True { +1 } when $_ =:= False { -1 } when !*.defined { 0 } when $_ !~~ Numeric { .so ?? 1 !! -1 } when 0 { 0 } when Numeric { $_ div .abs } default { .so ?? 1 !! -1 } } ::?CLASS.new: %anti{$key} } method is-true { self > 0 } method is-false { self < 0 } method is-unknown { self == 0 } multi method ACCEPTS( ::?CLASS:D: ::?CLASS:D $other ) { self == $other } method not(--> ::?CLASS) { (-1 * self).Ternary } method so { self } method Bool { return Bool without self; $.is-true } proto method COERCE($) { * } multi method COERCE(Bool:D $ where *.so ) { ::?CLASS(+1) } multi method COERCE(Bool:D $ where *.not) { ::?CLASS(-1) } multi method COERCE(Bool:U) { ::?CLASS( 0) } }