Skip to content

Commit

Permalink
feat: varidic multiple values
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Sep 6, 2024
1 parent c4a9dc5 commit 7bcd4e4
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions conv/conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ func String(val any) string {
}
}

// Strings returns the string slice representation of the values.
func Strings(vals ...any) []string {
strs := make([]string, len(vals))
for i, val := range vals {
strs[i] = String(val)
}

return strs
}

// Bool returns the boolean representation of the value.
// nolint:gocyclo
func Bool(val any) bool {
Expand Down Expand Up @@ -59,6 +69,16 @@ func Bool(val any) bool {
}
}

// Bools returns the boolean slice representation of the values.
func Bools(vals ...any) []bool {
bools := make([]bool, len(vals))
for i, val := range vals {
bools[i] = Bool(val)
}

return bools
}

// Int returns the integer representation of the value.
// nolint:gocyclo
func Int(val any) int {
Expand Down Expand Up @@ -191,6 +211,16 @@ func Int(val any) int {
}
}

// Ints returns the integer slice representation of the values.
func Ints(vals ...any) []int {
ints := make([]int, len(vals))
for i, val := range vals {
ints[i] = Int(val)
}

return ints
}

// Bytes returns the byte slice representation of the value.
func Bytes(val any) []byte {
switch val := val.(type) {
Expand Down

0 comments on commit 7bcd4e4

Please sign in to comment.