示例#1
0
文件: fp_test.go 项目: xdave/fp
func ExampleMapSliceString() {
	input := []string{"Hello", "World"}
	fmt.Println(fp.Map(input, func(item string, i int) string {
		return strings.ToUpper(item)
	}))
	// Output: [HELLO WORLD]
}
示例#2
0
文件: fp_test.go 项目: xdave/fp
func ExampleMapSliceInt() {
	input := []int{1, 2, 3, 4, 5}
	fmt.Println(fp.Map(input, func(item, i int) int {
		return item * 5
	}))
	// Output: [5 10 15 20 25]
}
示例#3
0
文件: fp_test.go 项目: xdave/fp
func ExampleMapMapStringInt() {
	input := map[string]int{"two": 1, "four": 2, "six": 3, "eight": 4}
	result := fp.Map(input, func(item int, i string) int {
		return item * 2
	}).(map[string]int)
	fmt.Println(result["two"], result["four"], result["six"], result["eight"])
	// Output: 2 4 6 8
}
示例#4
0
文件: fp_test.go 项目: xdave/fp
func ExampleMapReduceSlice() {
	input := []int{1, 2, 3, 4}
	fmt.Println(fp.Reduce(fp.Map(input, func(item, i int) int {
		return item * 5
	}), func(a, b int) int {
		return a + b
	}))
	// Output: 50
}
示例#5
0
文件: fp_test.go 项目: xdave/fp
func TestMapWrongTypePanics(t *testing.T) {
	defer func() {
		r := recover()
		if r == nil {
			t.Errorf("Did not panic as expected")
		}
	}()
	input := "someOddType"
	fp.Map(input, func() {})
}