From 407b62d3f12eece919463f556c798661f5aabbbf Mon Sep 17 00:00:00 2001 From: snamiki1212 Date: Wed, 2 Oct 2024 01:54:43 +0900 Subject: [PATCH] docs: fix example README, add playground (FromSlicePtrOr) (#541) * doc: update FromSlicePtrOr example in README * doc: add playground for FromSlicePtrOr * Update README.md --------- Co-authored-by: Samuel Berthe --- README.md | 4 +++- type_manipulation.go | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 22b710f1..73c33223 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{&str1, nil, &str2}, "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. 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 {