From a4ea39274e48ea7d30a01cfe721526957836b617 Mon Sep 17 00:00:00 2001 From: snamiki1212 Date: Sun, 29 Sep 2024 22:43:39 +0900 Subject: [PATCH 1/3] doc: update FromSlicePtrOr example in README --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 22b710f1..ddabc22d 100644 --- a/README.md +++ b/README.md @@ -2759,10 +2759,12 @@ Returns a slice with the pointer values or the fallback value. str1 := "hello" str2 := "world" -ptr := lo.FromSlicePtrOr[string]([]*string{&str1, &str2, "fallback value"}) +ptr := lo.FromSlicePtrOr[string]([]*string{&str1, &str2, nil}, "fallback value") // []string{"hello", "world", "fallback value"} ``` +[[play](https://go.dev/play/p/lbunFvzlUDX)] + ### ToAnySlice Returns a slice with all elements mapped to `any` type. From deb31bd117b9c7d939b4036af63d8b7fe11dae26 Mon Sep 17 00:00:00 2001 From: snamiki1212 Date: Sun, 29 Sep 2024 22:44:42 +0900 Subject: [PATCH 2/3] doc: add playground for FromSlicePtrOr --- type_manipulation.go | 1 + 1 file changed, 1 insertion(+) diff --git a/type_manipulation.go b/type_manipulation.go index 448abe96..1fdd37b8 100644 --- a/type_manipulation.go +++ b/type_manipulation.go @@ -70,6 +70,7 @@ func FromSlicePtr[T any](collection []*T) []T { } // FromSlicePtrOr returns a slice with the pointer values or the fallback value. +// Play: https://go.dev/play/p/lbunFvzlUDX func FromSlicePtrOr[T any](collection []*T, fallback T) []T { return Map(collection, func(x *T, _ int) T { if x == nil { From 2442798a652fb3ea2e53a7000747da0214c1bec8 Mon Sep 17 00:00:00 2001 From: Samuel Berthe Date: Tue, 1 Oct 2024 18:54:36 +0200 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ddabc22d..73c33223 100644 --- a/README.md +++ b/README.md @@ -2759,7 +2759,7 @@ Returns a slice with the pointer values or the fallback value. str1 := "hello" str2 := "world" -ptr := lo.FromSlicePtrOr[string]([]*string{&str1, &str2, nil}, "fallback value") +ptr := lo.FromSlicePtrOr([]*string{&str1, nil, &str2}, "fallback value") // []string{"hello", "world", "fallback value"} ```