davideisinger.com

My personal website
Log | Files | Refs | README

commit 2636740b4a42af3c495b779c89a187a32cacb600
parent 9de6711271847631e67e1a578f0635008d178503
Author: David Eisinger <[email protected]>
Date:   Thu, 13 Jul 2023 22:27:48 -0400

Go type conversion/assertion

Diffstat:
Mcontent/notes/golang/index.md | 5+++++
1 file changed, 5 insertions(+), 0 deletions(-)

diff --git 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