From fe096bf93990a770a5ab0f5664ec84dc2687eb54 Mon Sep 17 00:00:00 2001 From: David Eisinger Date: Sun, 16 Jul 2023 22:30:48 -0400 Subject: [PATCH] Stringers --- content/notes/golang/index.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/content/notes/golang/index.md b/content/notes/golang/index.md index a9c134f..58652f8 100644 --- a/content/notes/golang/index.md +++ b/content/notes/golang/index.md @@ -136,6 +136,9 @@ I find [Go][1] really compelling, even though it's not super applicable to my jo * `rand.Intn`: random integer between 0 and the specified int * `rand.Float64`: random float between 0.0. and 1.0 * `rand.Shuffle`: randomize an array/slice; takes a length and a swap function +* Stringers + * Define a `String() string` method for types so that `fmt` knows how to stringify them + * E.g. `fmt.Sprintf("%s", yourThing)` will call `yourThing`'s `String()` function [17]: https://stackoverflow.com/a/40951013 [18]: https://go.dev/doc/effective_go#named-results