adding lop.Map and lop.ForEach

This commit is contained in:
Samuel Berthe
2022-03-03 16:15:17 +01:00
parent 50e56b15b6
commit 2566a935f2
7 changed files with 112 additions and 25 deletions

24
parallel/slice_test.go Normal file
View File

@@ -0,0 +1,24 @@
package parallel
import (
"testing"
"strconv"
"github.com/stretchr/testify/assert"
)
func TestMap(t *testing.T) {
is := assert.New(t)
result1 := Map[int, string]([]int{1, 2, 3, 4}, func(x int, _ int) string {
return "Hello"
})
result2 := Map[int64, string]([]int64{1, 2, 3, 4}, func(x int64, _ int) string {
return strconv.FormatInt(x, 10)
})
is.Equal(len(result1), 4)
is.Equal(len(result2), 4)
is.Equal(result1, []string{"Hello", "Hello", "Hello", "Hello"})
is.Equal(result2, []string{"1", "2", "3", "4"})
}