mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
chore: rename dbgen package files and remove small file (#7997)
This commit is contained in:
@ -525,3 +525,40 @@ func must[V any](v V, err error) V {
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func takeFirstIP(values ...net.IPNet) net.IPNet {
|
||||
return takeFirstF(values, func(v net.IPNet) bool {
|
||||
return len(v.IP) != 0 && len(v.Mask) != 0
|
||||
})
|
||||
}
|
||||
|
||||
// takeFirstSlice implements takeFirst for []any.
|
||||
// []any is not a comparable type.
|
||||
func takeFirstSlice[T any](values ...[]T) []T {
|
||||
return takeFirstF(values, func(v []T) bool {
|
||||
return len(v) != 0
|
||||
})
|
||||
}
|
||||
|
||||
// takeFirstF takes the first value that returns true
|
||||
func takeFirstF[Value any](values []Value, take func(v Value) bool) Value {
|
||||
for _, v := range values {
|
||||
if take(v) {
|
||||
return v
|
||||
}
|
||||
}
|
||||
// If all empty, return the last element
|
||||
if len(values) > 0 {
|
||||
return values[len(values)-1]
|
||||
}
|
||||
var empty Value
|
||||
return empty
|
||||
}
|
||||
|
||||
// takeFirst will take the first non-empty value.
|
||||
func takeFirst[Value comparable](values ...Value) Value {
|
||||
var empty Value
|
||||
return takeFirstF(values, func(v Value) bool {
|
||||
return v != empty
|
||||
})
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
package dbgen
|
||||
|
||||
import "net"
|
||||
|
||||
func takeFirstIP(values ...net.IPNet) net.IPNet {
|
||||
return takeFirstF(values, func(v net.IPNet) bool {
|
||||
return len(v.IP) != 0 && len(v.Mask) != 0
|
||||
})
|
||||
}
|
||||
|
||||
// takeFirstSlice implements takeFirst for []any.
|
||||
// []any is not a comparable type.
|
||||
func takeFirstSlice[T any](values ...[]T) []T {
|
||||
return takeFirstF(values, func(v []T) bool {
|
||||
return len(v) != 0
|
||||
})
|
||||
}
|
||||
|
||||
// takeFirstF takes the first value that returns true
|
||||
func takeFirstF[Value any](values []Value, take func(v Value) bool) Value {
|
||||
for _, v := range values {
|
||||
if take(v) {
|
||||
return v
|
||||
}
|
||||
}
|
||||
// If all empty, return the last element
|
||||
if len(values) > 0 {
|
||||
return values[len(values)-1]
|
||||
}
|
||||
var empty Value
|
||||
return empty
|
||||
}
|
||||
|
||||
// takeFirst will take the first non-empty value.
|
||||
func takeFirst[Value comparable](values ...Value) Value {
|
||||
var empty Value
|
||||
return takeFirstF(values, func(v Value) bool {
|
||||
return v != empty
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user