-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simpler "custom unit" example? #16
Comments
No advantage, its just a trivial usage example. Feel free to submit a patch to update the readme with more examples if you want. |
@dmoles if you send a patch, I would also recommend adding a number, just for a more illustrative example, something like func main() {
fmt.Printf("8 pc = %f ly\n", (8 * Parsec).LightYears())
fmt.Printf("4 ly = %f pc\n", ToParsecs(4 * unit.LightYear))
} |
I'm not changing anything right now. Patches are welcome. |
Thanks. I'll submit a patch after I've played around a bit more with the library and have confidence in my example. |
It's not quite as clean as it would be in some languages since Go doesn't let you attach extension methods to existing types, but this seems easier than the
int
type + cast example:Prints:
Is there an advantage to the
type MyUnit int
(or in this case I supposetype Parsec float64
) approach over this?The text was updated successfully, but these errors were encountered: