Skip to content

Instantly share code, notes, and snippets.

@potapovkd
potapovkd / fibonacci_closure.go
Created November 8, 2025 08:33
Fibonacci Closure
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
f0 := 0
f1 := 1
return func() int {
@potapovkd
potapovkd / first_defer_gotcha.go
Created November 7, 2025 23:48
First gotcha with defer in Go
package main
import "fmt"
func main() {
i := 0
defer fmt.Println(i)
i += 1
fmt.Println("hello")
}
@potapovkd
potapovkd / second_defer_gotcha.go
Last active November 7, 2025 23:47
Second gotcha with defer in Go
package main
import "fmt"
func main() {
fmt.Println("counting")
for i := 0; i < 5; i++ {
defer fmt.Println(i)
}