diff --git a/docs/2022-07-10-bootstrap-go.html b/docs/2022-07-10-bootstrap-go.html index 60ed1cc..f205686 100644 --- a/docs/2022-07-10-bootstrap-go.html +++ b/docs/2022-07-10-bootstrap-go.html @@ -340,6 +340,13 @@ internal
// Ptr takes in non-pointer and returns a pointer
 func Ptr[T any](v T) *T {
 	return &v
+}
+ +

Return zero value:

+
+
func Zero[T any]() T {
+  var zero T
+  return zero
 }

@@ -883,6 +890,11 @@ fieldalignment -fix ./internal/business/*.go >Go generic: non-ptr to ptr +
  • + Crimes with Go Generics +
  • diff --git a/posts/2022-07-10-bootstrap-go.md b/posts/2022-07-10-bootstrap-go.md index 5a315e8..53a7280 100644 --- a/posts/2022-07-10-bootstrap-go.md +++ b/posts/2022-07-10-bootstrap-go.md @@ -201,6 +201,15 @@ func Ptr[T any](v T) *T { } ``` +Return zero value: + +```go +func Zero[T any]() T { + var zero T + return zero +} +``` + ## External libs ### No need `vendor` @@ -498,3 +507,4 @@ go clean -cache -testcache -modcache -fuzzcache -x - [Making SQLite faster in Go](https://turriate.com/articles/making-sqlite-faster-in-go) - [Advanced Go Concurrency](https://encore.dev/blog/advanced-go-concurrency) - [Go generic: non-ptr to ptr](https://danielms.site/zet/2023/go-generic-non-ptr-to-ptr/) +- [Crimes with Go Generics](https://xeiaso.net/blog/gonads-2022-04-24)