make allocs more obvious
This commit is contained in:
parent
066eb8688c
commit
2d4b3a96cd
20
map.go
20
map.go
|
@ -7,27 +7,27 @@ func Map[T any](xs []T, fx func(T) T) []T {
|
||||||
return xs
|
return xs
|
||||||
}
|
}
|
||||||
|
|
||||||
func MapV[T, V any](xs []T, fx func(T) V) (ov []V) {
|
func MapV[T, V any](xs []T, fx func(T) V) []V {
|
||||||
ov = make([]V, len(xs))
|
ov := make([]V, len(xs))
|
||||||
for i, v := range xs {
|
for i, v := range xs {
|
||||||
ov[i] = fx(v)
|
ov[i] = fx(v)
|
||||||
}
|
}
|
||||||
return
|
return ov
|
||||||
}
|
}
|
||||||
|
|
||||||
func MapError[T any](xs []T, fx func(T) (T, error)) (ov []T, oe []error) {
|
func MapError[T any](xs []T, fx func(T) (T, error)) ([]T, []error) {
|
||||||
oe = make([]error, len(xs))
|
oe := make([]error, len(xs))
|
||||||
for i, v := range xs {
|
for i, v := range xs {
|
||||||
xs[i], oe[i] = fx(v)
|
xs[i], oe[i] = fx(v)
|
||||||
}
|
}
|
||||||
return
|
return xs, oe
|
||||||
}
|
}
|
||||||
|
|
||||||
func MapErrorV[T, V any](xs []T, fx func(T) (V, error)) (ov []V, oe []error) {
|
func MapErrorV[T, V any](xs []T, fx func(T) (V, error)) ([]V, []error) {
|
||||||
ov = make([]V, len(xs))
|
ov := make([]V, len(xs))
|
||||||
oe = make([]error, len(xs))
|
oe := make([]error, len(xs))
|
||||||
for i, v := range xs {
|
for i, v := range xs {
|
||||||
ov[i], oe[i] = fx(v)
|
ov[i], oe[i] = fx(v)
|
||||||
}
|
}
|
||||||
return
|
return ov, oe
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue