Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9440b3d

Browse files
authored
chore: rename dbgen package files and remove small file (#7997)
1 parent 1d0fae8 commit 9440b3d

File tree

3 files changed

+37
-40
lines changed

3 files changed

+37
-40
lines changed

coderd/database/dbgen/generator.go renamed to coderd/database/dbgen/dbgen.go

+37
Original file line numberDiff line numberDiff line change
@@ -525,3 +525,40 @@ func must[V any](v V, err error) V {
525525
}
526526
return v
527527
}
528+
529+
func takeFirstIP(values ...net.IPNet) net.IPNet {
530+
return takeFirstF(values, func(v net.IPNet) bool {
531+
return len(v.IP) != 0 && len(v.Mask) != 0
532+
})
533+
}
534+
535+
// takeFirstSlice implements takeFirst for []any.
536+
// []any is not a comparable type.
537+
func takeFirstSlice[T any](values ...[]T) []T {
538+
return takeFirstF(values, func(v []T) bool {
539+
return len(v) != 0
540+
})
541+
}
542+
543+
// takeFirstF takes the first value that returns true
544+
func takeFirstF[Value any](values []Value, take func(v Value) bool) Value {
545+
for _, v := range values {
546+
if take(v) {
547+
return v
548+
}
549+
}
550+
// If all empty, return the last element
551+
if len(values) > 0 {
552+
return values[len(values)-1]
553+
}
554+
var empty Value
555+
return empty
556+
}
557+
558+
// takeFirst will take the first non-empty value.
559+
func takeFirst[Value comparable](values ...Value) Value {
560+
var empty Value
561+
return takeFirstF(values, func(v Value) bool {
562+
return v != empty
563+
})
564+
}

coderd/database/dbgen/take.go

-40
This file was deleted.

0 commit comments

Comments
 (0)