Skip to content

Instantly share code, notes, and snippets.

@scbizu
Created June 6, 2016 06:46
Show Gist options
  • Save scbizu/f55ba8991337372be1886c60c0f7f495 to your computer and use it in GitHub Desktop.
Save scbizu/f55ba8991337372be1886c60c0f7f495 to your computer and use it in GitHub Desktop.
函数编程思维的闭包例子的Golang实现
package main
import "fmt"
type Studnet struct {
name string
age int
}
func Average(age int) func(stu *Studnet) bool {
return func(stu *Studnet) bool {
return stu.age > age
}
}
func main() {
Nace := &Studnet{"nace", 18}
Bizu := &Studnet{"Bizu", 20}
test := Average(19)
fmt.Println(test(Nace))
fmt.Println(test(Bizu))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment