Skip to content

Commit fd12095

Browse files
authored
Add files via upload
1 parent 225c911 commit fd12095

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

short_if.go

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package funk
2+
3+
func ShortIf(condition bool, a interface{}, b interface{}) interface{} {
4+
if condition {
5+
return a
6+
}
7+
return b
8+
}

short_if_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package funk
2+
3+
import (
4+
"testing"
5+
"github.com/stretchr/testify/assert"
6+
)
7+
8+
func TestShortIf(t *testing.T) {
9+
is := assert.New(t)
10+
11+
r := ShortIf(10>5 , 10, 5)
12+
is.Equal(r,10)
13+
14+
r = ShortIf(10.0 == 10 , "yes", "no")
15+
is.Equal(r,"yes")
16+
17+
r = ShortIf('a'=='b',"equal chars","unequal chars")
18+
is.Equal(r,"unequal chars")
19+
20+
r = ShortIf("abc"=="abc","Same string","Different strings")
21+
is.Equal(r,"Same string")
22+
23+
type testStruct struct{}
24+
a := testStruct{}
25+
b := testStruct{}
26+
r = ShortIf(a==b , &a, &b)
27+
is.Equal(r,&b)
28+
29+
}

0 commit comments

Comments
 (0)