github.com/l3x/learn-fp-go@v0.0.0-20171228022418-7639825d0b71/1-functional-fundamentals/ch03-hof/01_cps/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 ) 6 7 func main() { 8 9 factorial(4, func(result int) { 10 fmt.Println(result) 11 }) 12 } 13 14 func factorial(x int, next func(int)) { 15 if x == 0 { 16 next(1) 17 } else { 18 factorial(x-1, func(y int) { 19 next(x * y) 20 }) 21 } 22 }