Skip to content

Instantly share code, notes, and snippets.

@mfirhas
Last active September 20, 2021 04:39
Show Gist options
  • Save mfirhas/5bbe4d09a2e6398113b0a76f9e56aacf to your computer and use it in GitHub Desktop.
Save mfirhas/5bbe4d09a2e6398113b0a76f9e56aacf to your computer and use it in GitHub Desktop.
Print your name 1000 times without looping in Go
package main
// Y = πœ†π‘“.(πœ†π‘₯.𝑓(π‘₯π‘₯))(πœ†π‘₯.𝑓(π‘₯π‘₯))
import "fmt"
type (
F func(string, int)
FF func(F) F
YF func(YF) F
)
func Y(ff FF) F {
g := func(y YF) F {
return ff(func(name string, n int) {
y(y)(name, n)
})
}
return g(g)
}
func Print(p F) F {
return func(name string, n int) {
if n > 0 {
fmt.Printf("%d. %s \n", n, name)
p(name, n-1)
}
}
}
func main() {
printMyName := Y(Print)
printMyName("Fathir", 1000)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment