Skip to content

Instantly share code, notes, and snippets.

@haya14busa

haya14busa/goal.go

Created Jul 20, 2020
Embed
What would you like to do?
package main
import (
"fmt"
)
func main() {
fmt.Println(g("al"))
fmt.Println(g()("al"))
fmt.Println(g()()("al"))
fmt.Println(g()()()("al"))
fmt.Println(g()()()()("al"))
fmt.Println(g()()()()()("al"))
fmt.Println(g()()()()()()("al"))
fmt.Println(g()("O")()("O")("al")("!"))
fmt.Println(g()()("gle"))
fmt.Println(g()("lang"))
}
type F func(...interface{}) F
func (f F) String() (out string) {
f(&out)
return
}
func g(al ...interface{}) F {
var f F
out := "g"
f = func(al ...interface{}) F {
if len(al) != 1 {
out += "o"
return f
}
switch a := al[0].(type) {
case string:
out += a
case *string:
*a = out
}
return f
}
return f(al...)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment