diff --git a/example/main.go b/example/return/main.go similarity index 100% rename from example/main.go rename to example/return/main.go diff --git a/example/return_by_func/main.go b/example/return_by_func/main.go new file mode 100644 index 0000000..4c6b949 --- /dev/null +++ b/example/return_by_func/main.go @@ -0,0 +1,22 @@ +package main + +import ( + "fmt" + if_expression "github.com/golang-infrastructure/go-if-expression" +) + +func main() { + + r := if_expression.ReturnByFunc(true, func() string { + fmt.Println("True分支被执行了") + return "是" + }, func() string { + fmt.Println("False分支被执行了") + return "否" + }) + fmt.Println(r) + // Output: + // True分支被执行了 + // 是 + +}