Skip to content

Instantly share code, notes, and snippets.

@haya14busa
Created July 20, 2020 02:53
Show Gist options
  • Save haya14busa/51ee7fbc2db0eb6339f9fa4120e354b2 to your computer and use it in GitHub Desktop.
Save haya14busa/51ee7fbc2db0eb6339f9fa4120e354b2 to your computer and use it in GitHub Desktop.
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