Anonymous user
Catamorphism: Difference between revisions
→{{header|Go}}: Idiomatic for range (plus gofmt and remove trailing blank line)
m (→{{header|Go}}: Condense code) |
(→{{header|Go}}: Idiomatic for range (plus gofmt and remove trailing blank line)) |
||
Line 183:
func main() {
n := []int
fmt.Println(reduce(add, n))
fmt.Println(reduce(sub, n))
Line 190:
}
func add(a int, b int) int { return a + b }
func sub(a int, b int) int { return a - b }
func mul(a int, b int) int { return a * b }
func reduce
r := m[0]
for
r = rf(r,
}
return r
}</lang>▼
▲</lang>
{{out}}
<pre>
|