Skip to content

Commit 05b7896

Browse files
committed
update
1 parent 897b0e3 commit 05b7896

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

logic_go1.18.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//go:build go1.18
2+
3+
package com
4+
5+
import "reflect"
6+
7+
func IfTrue[V any](condition bool, yesValue V, noValue V) V {
8+
if condition {
9+
return yesValue
10+
}
11+
return noValue
12+
}
13+
14+
func IfFalse[V any](condition bool, yesValue V, noValue V) V {
15+
if !condition {
16+
return yesValue
17+
}
18+
return noValue
19+
}
20+
21+
func IfZero[V any](condition any, yesValue V, noValue V) V {
22+
if reflect.ValueOf(condition).IsZero() {
23+
return yesValue
24+
}
25+
return noValue
26+
}

0 commit comments

Comments
 (0)