update: directory structure
This commit is contained in:
52
advfuncs/02-func-values/main.go
Normal file
52
advfuncs/02-func-values/main.go
Normal file
@ -0,0 +1,52 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type filterFunc func(int) bool
|
||||
|
||||
func main() {
|
||||
signatures()
|
||||
funcValues()
|
||||
}
|
||||
|
||||
func isEven(n int) bool {
|
||||
return n%2 == 0
|
||||
}
|
||||
|
||||
func isOdd(m int) bool {
|
||||
return m%2 == 1
|
||||
}
|
||||
|
||||
func signatures() {
|
||||
fmt.Println("••• FUNC SIGNATURES (TYPES) •••")
|
||||
fmt.Printf("isEven : %T\n", isEven)
|
||||
fmt.Printf("isOdd : %T\n", isOdd)
|
||||
}
|
||||
|
||||
func funcValues() {
|
||||
fmt.Println("\n••• FUNC VALUES (VARS) •••")
|
||||
|
||||
// var value func(int) bool
|
||||
var value filterFunc
|
||||
fmt.Printf("value nil? : %t\n", value == nil)
|
||||
|
||||
value = isEven
|
||||
fmt.Printf("value(2) : %t\n", value(2))
|
||||
fmt.Printf("isEven(2) : %t\n", isEven(2))
|
||||
|
||||
value = isOdd
|
||||
fmt.Printf("value(1) : %t\n", value(1))
|
||||
fmt.Printf("isOdd(1) : %t\n", isOdd(1))
|
||||
|
||||
fmt.Printf("value nil? : %t\n", value == nil)
|
||||
fmt.Printf("value : %p\n", value)
|
||||
fmt.Printf("isEven : %p\n", isEven)
|
||||
fmt.Printf("isOdd : %p\n", isOdd)
|
||||
}
|
Reference in New Issue
Block a user