Example #1
0
File: fp_test.go Project: 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]
}
Example #2
0
File: fp_test.go Project: 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]
}
Example #3
0
File: fp_test.go Project: 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
}
Example #4
0
File: fp_test.go Project: 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
}
Example #5
0
File: fp_test.go Project: 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() {})
}