From 2636740b4a42af3c495b779c89a187a32cacb600 Mon Sep 17 00:00:00 2001 From: David Eisinger Date: Thu, 13 Jul 2023 22:27:48 -0400 Subject: [PATCH] Go type conversion/assertion --- content/notes/golang/index.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/content/notes/golang/index.md b/content/notes/golang/index.md index 37aa9f0..026facf 100644 --- a/content/notes/golang/index.md +++ b/content/notes/golang/index.md @@ -108,6 +108,11 @@ I find [Go][1] really compelling, even though it's not super applicable to my jo > The reason for this is because the names are not really important for someone calling a method or a function. What matters is the types of the parameters and their order. This is detailed in this answer: [Getting method parameter names in Golang](https://stackoverflow.com/questions/31377433/getting-method-parameter-names-in-golang/31377793#31377793) * [Named result parameters][18] +* Type Conversion & Assertion + * Built-in functions for conversion (`float64`, `strconv.Atoi`) + * `if v, ok := fnb.(FancyNumber); ok {` (`v` is a `FancyNumber` if `ok` is true) + * `switch v := i.(type) {` (case per type, `v` is `i` cast to that type) + [17]: https://stackoverflow.com/a/40951013 [18]: https://go.dev/doc/effective_go#named-results