Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conv.ToStrings function #354

Merged
merged 1 commit into from
Jul 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions conv/conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ func ToString(in interface{}) string {
return fmt.Sprint(in)
}

// ToStrings -
func ToStrings(in ...interface{}) []string {
out := make([]string, len(in))
for i, v := range in {
out[i] = ToString(v)
}
return out
}

// MustParseInt - wrapper for strconv.ParseInt that returns 0 in the case of error
func MustParseInt(s string, base, bitSize int) int64 {
i, _ := strconv.ParseInt(s, base, bitSize)
Expand Down
6 changes: 5 additions & 1 deletion docs/content/functions/conv.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,8 @@ Converts the inputs to an array of `float64`s

## `conv.ToString`

Converts the input (of any type) to a `string`
Converts the input (of any type) to a `string`

## `conv.ToStrings`

Converts the inputs (of any type) to an array of `string`s
11 changes: 8 additions & 3 deletions funcs/conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ func (f *ConvFuncs) ToInt(in interface{}) int {

// ToInt64s -
func (f *ConvFuncs) ToInt64s(in ...interface{}) []int64 {
return conv.ToInt64s(in)
return conv.ToInt64s(in...)
}

// ToInts -
func (f *ConvFuncs) ToInts(in ...interface{}) []int {
return conv.ToInts(in)
return conv.ToInts(in...)
}

// ToFloat64 -
Expand All @@ -106,14 +106,19 @@ func (f *ConvFuncs) ToFloat64(in interface{}) float64 {

// ToFloat64s -
func (f *ConvFuncs) ToFloat64s(in ...interface{}) []float64 {
return conv.ToFloat64s(in)
return conv.ToFloat64s(in...)
}

// ToString -
func (f *ConvFuncs) ToString(in interface{}) string {
return conv.ToString(in)
}

// ToStrings -
func (f *ConvFuncs) ToStrings(in ...interface{}) []string {
return conv.ToStrings(in...)
}

// Default -
func (f *ConvFuncs) Default(def, in interface{}) interface{} {
if truth, ok := template.IsTrue(in); truth && ok {
Expand Down