From 2d4b3a96cd3f5ad895a9c801048d43e223a10f85 Mon Sep 17 00:00:00 2001 From: a Date: Sat, 26 Mar 2022 17:29:43 -0500 Subject: [PATCH] make allocs more obvious --- map.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/map.go b/map.go index 562fae4..c72559b 100644 --- a/map.go +++ b/map.go @@ -7,27 +7,27 @@ func Map[T any](xs []T, fx func(T) T) []T { return xs } -func MapV[T, V any](xs []T, fx func(T) V) (ov []V) { - ov = make([]V, len(xs)) +func MapV[T, V any](xs []T, fx func(T) V) []V { + ov := make([]V, len(xs)) for i, v := range xs { ov[i] = fx(v) } - return + return ov } -func MapError[T any](xs []T, fx func(T) (T, error)) (ov []T, oe []error) { - oe = make([]error, len(xs)) +func MapError[T any](xs []T, fx func(T) (T, error)) ([]T, []error) { + oe := make([]error, len(xs)) for i, v := range xs { 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) { - ov = make([]V, len(xs)) - oe = make([]error, len(xs)) +func MapErrorV[T, V any](xs []T, fx func(T) (V, error)) ([]V, []error) { + ov := make([]V, len(xs)) + oe := make([]error, len(xs)) for i, v := range xs { ov[i], oe[i] = fx(v) } - return + return ov, oe }