Created
August 1, 2020 09:06
-
-
Save spytheman/3aaf3a3a1126f3585a853e9aed9eb021 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| type SuccessCode int | |
| type FailureCode int | |
| type Code = SuccessCode | FailureCode | |
| fn (x SuccessCode) hex() string { return 'my hex: ' + int(x).hex() } | |
| // | |
| fn (x SuccessCode) str() string { return 'SC(' + int(x).str() +')' } | |
| fn (x FailureCode) str() string { return 'FC(' + int(x).str() +')' } | |
| fn (x Code) str() string { | |
| mut res := '' | |
| match x { | |
| SuccessCode { res = x.str() } | |
| FailureCode { res = x.str() } | |
| } | |
| return 'Code( ' +typeof(x)+ ' : $res )' | |
| } | |
| fn main() { | |
| s := Code( SuccessCode(1) ) | |
| f := Code( FailureCode(2) ) | |
| println('calling hex for SC: ' + SuccessCode(1023).hex()) | |
| println('calling hex for FC: ' + FailureCode(1023).hex()) | |
| all := [s,f] | |
| for x in all { | |
| println('x: $x') | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment