@kjk1/

gobook function variable 2

Go

No description

fork
loading
Files
  • main.go

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.20622932484673995","path":"main.go","file":{"path":"main.go","content":{"asEncoding":{"base64":"cGFja2FnZSBtYWluCgppbXBvcnQgImZtdCIKCi8vIDpzaG93IHN0YXJ0CmZ1bmMgZnVuY0FkZChhLCBiIGludCkgaW50IHsKCXJldHVybiBhICsgYgp9CgpmdW5jIHJ1bkZ1bmMoYSwgYiBpbnQsIGludE9wIGZ1bmMoaW50LCBpbnQpIGludCkgewoJZm10LlByaW50ZigiaW50T3AoJWQsICVkKSA9ICVkXG4iLCBhLCBiLCBpbnRPcChhLCBiKSkKfQoKZnVuYyBtYWluKCkgewoJcnVuRnVuYygyLCAzLCBmdW5jQWRkKQoKCS8vIHdlIGNhbiBwYXNzIGxpdGVyYWwgZnVuY3Rpb25zIGFzIHdlbGwKCXJ1bkZ1bmMoMiwgMywgZnVuYyhhLCBiIGludCkgaW50IHsKCQlyZXR1cm4gYSAqIGIKCX0pCn0KCi8vIDpzaG93IGVuZA=="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package main

import "fmt"

// :show start
func funcAdd(a, b int) int {
	return a + b
}

func runFunc(a, b int, intOp func(int, int) int) {
	fmt.Printf("intOp(%d, %d) = %d\n", a, b, intOp(a, b))
}

func main() {
	runFunc(2, 3, funcAdd)

	// we can pass literal functions as well
	runFunc(2, 3, func(a, b int) int {
		return a * b
	})
}

// :show end