mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-15 18:22:27 +08:00
refactor: change common package to condition package
This commit is contained in:
@@ -1,10 +0,0 @@
|
|||||||
package common
|
|
||||||
|
|
||||||
// TernaryOperator if true return trueValue else return falseValue
|
|
||||||
func TernaryOperator[T any](isTrue bool, trueValue T, falseValue T) T {
|
|
||||||
if isTrue {
|
|
||||||
return trueValue
|
|
||||||
} else {
|
|
||||||
return falseValue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
14
condition/condition.go
Normal file
14
condition/condition.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// Copyright 2021 dudaodong@gmail.com. All rights reserved.
|
||||||
|
// Use of this source code is governed by MIT license
|
||||||
|
|
||||||
|
// Package condition contains some functions for conditional judgment. eg. And, Or, TernaryOperator ...
|
||||||
|
package condition
|
||||||
|
|
||||||
|
// TernaryOperator if true return trueValue else return falseValue
|
||||||
|
func TernaryOperator[T any](isTrue bool, trueValue T, falseValue T) T {
|
||||||
|
if isTrue {
|
||||||
|
return trueValue
|
||||||
|
} else {
|
||||||
|
return falseValue
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
package common
|
package condition
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/duke-git/lancet/v2/internal"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/duke-git/lancet/v2/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTernaryOperator(t *testing.T) {
|
func TestTernaryOperator(t *testing.T) {
|
||||||
Reference in New Issue
Block a user