Example #1
0
File: fp_test.go Project: xdave/fp
func ExampleReduceSlice() {
	input := []float64{1.0, 2.0, 3.0, 4.0, 5.0}
	fmt.Println(fp.Reduce(input, func(a, b float64) float64 {
		return a + b
	}))
	// Output: 15
}
Example #2
0
File: fp_test.go Project: xdave/fp
func ExampleReduceMap() {
	input := map[string]int{"foo": 5, "bar": 6, "baz": 7}
	fmt.Println(fp.Reduce(input, func(a, b int) int {
		return a * b
	}))
	// Output: 210
}
Example #3
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 #4
0
File: fp_test.go Project: xdave/fp
func TestReduceWrongTypePanics(t *testing.T) {
	defer func() {
		r := recover()
		if r == nil {
			t.Errorf("Did not panic as expected")
		}
	}()
	input := "someOddType"
	fp.Reduce(input, func() {})
}