From b6ab9b7cbfe1a82da63b4909cfae72ebdf84a071 Mon Sep 17 00:00:00 2001 From: CC11001100 Date: Fri, 11 Aug 2023 00:19:45 +0800 Subject: [PATCH] =?UTF-8?q?examples:=20=E5=A2=9E=E5=8A=A0API=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/{ => return}/main.go | 0 example/return_by_func/main.go | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+) rename example/{ => return}/main.go (100%) create mode 100644 example/return_by_func/main.go 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分支被执行了 + // 是 + +}