Пример #1
0
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
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
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
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
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() {})
}