We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fd52e8f commit 5175c86Copy full SHA for 5175c86
intra/core/slices.go
@@ -41,6 +41,14 @@ func FilterLeft[T any](arr []T, test TestFn[T]) (out []T) {
41
return out
42
}
43
44
+func Map[T, U any](arr []T, transform func(T) U) (out []U) {
45
+ out = make([]U, 0)
46
+ for _, x := range arr {
47
+ out = append(out, transform(x))
48
+ }
49
+ return out
50
+}
51
+
52
// WithoutElem returns arr (may be a copy) removing all occurrences of elem.
53
func WithoutElem[T comparable](arr []T, elem T) (out []T) {
54
if !slices.Contains(arr, elem) {
@@ -67,3 +75,13 @@ func WithElem[T comparable](s []T, add T) []T {
67
75
68
76
return append(s, add)
69
77
78
79
+func WithoutNils[T any](arr []T) (out []T) {
80
81
+ if IsNil(x) {
82
+ continue
83
84
+ out = append(out, x)
85
86
87
0 commit comments