Closures
func concatter() func(string) string {
doc := ""
return func(word string) string {
doc += word + " "
return doc
}
}
func main() {
harryPotterAggregator := concatter()
harryPotterAggregator("Mr.")
harryPotterAggregator("and")
harryPotterAggregator("Mrs.")
harryPotterAggregator("Dursley")
harryPotterAggregator("of")
harryPotterAggregator("number")
harryPotterAggregator("four,")
harryPotterAggregator("Privet")
fmt.Println(harryPotterAggregator("Drive"))
// Mr. and Mrs. Dursley of number four, Privet Drive
}Assignment
π§© The function definition
βοΈ Using it in action
π§ Visualization
β
TL;DR
Part
Meaning
βοΈ Bonus example
π§ Whatβs really happening
βοΈ What does adder() return?
adder() return?β
So when you later write:
π‘ Analogy
π Summary
Concept
Explanation