Skip to content

Commit 9440b3d

Browse files
authored
chore: rename dbgen package files and remove small file (coder#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

Lines changed: 37 additions & 0 deletions
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

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy