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 }
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 }
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 }
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() {}) }