github.com/switchupcb/yaegi@v0.10.2/_test/composite19.go (about)

     1  package main
     2  
     3  import "fmt"
     4  
     5  type fn func(string, string) bool
     6  
     7  var funcs = map[string]fn{
     8  	"less":    cmpLessFn,
     9  	"greater": cmpGreaterFn,
    10  	"none":     nil,
    11  }
    12  
    13  func cmpLessFn(a string, b string) bool {
    14  	return a < b
    15  }
    16  
    17  func cmpGreaterFn(a string, b string) bool {
    18  	return a > b
    19  }
    20  
    21  func main() {
    22  	for _, n := range []string{"less", "greater", "none"} {
    23  		f := funcs[n]
    24  		if f == nil {
    25  			continue
    26  		}
    27  		fmt.Println(f("a", "b"))
    28  	}
    29  }
    30  
    31  // Output:
    32  // true
    33  // false