Last active
September 20, 2021 04:39
-
-
Save mfirhas/5bbe4d09a2e6398113b0a76f9e56aacf to your computer and use it in GitHub Desktop.
Print your name 1000 times without looping in Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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