github.com/wangyougui/gf/v2@v2.6.5/container/gvar/gvar_slice.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/wangyougui/gf.
     6  
     7  package gvar
     8  
     9  import "github.com/wangyougui/gf/v2/util/gconv"
    10  
    11  // Ints converts and returns `v` as []int.
    12  func (v *Var) Ints() []int {
    13  	return gconv.Ints(v.Val())
    14  }
    15  
    16  // Int64s converts and returns `v` as []int64.
    17  func (v *Var) Int64s() []int64 {
    18  	return gconv.Int64s(v.Val())
    19  }
    20  
    21  // Uints converts and returns `v` as []uint.
    22  func (v *Var) Uints() []uint {
    23  	return gconv.Uints(v.Val())
    24  }
    25  
    26  // Uint64s converts and returns `v` as []uint64.
    27  func (v *Var) Uint64s() []uint64 {
    28  	return gconv.Uint64s(v.Val())
    29  }
    30  
    31  // Floats is alias of Float64s.
    32  func (v *Var) Floats() []float64 {
    33  	return gconv.Floats(v.Val())
    34  }
    35  
    36  // Float32s converts and returns `v` as []float32.
    37  func (v *Var) Float32s() []float32 {
    38  	return gconv.Float32s(v.Val())
    39  }
    40  
    41  // Float64s converts and returns `v` as []float64.
    42  func (v *Var) Float64s() []float64 {
    43  	return gconv.Float64s(v.Val())
    44  }
    45  
    46  // Strings converts and returns `v` as []string.
    47  func (v *Var) Strings() []string {
    48  	return gconv.Strings(v.Val())
    49  }
    50  
    51  // Interfaces converts and returns `v` as []interfaces{}.
    52  func (v *Var) Interfaces() []interface{} {
    53  	return gconv.Interfaces(v.Val())
    54  }
    55  
    56  // Slice is alias of Interfaces.
    57  func (v *Var) Slice() []interface{} {
    58  	return v.Interfaces()
    59  }
    60  
    61  // Array is alias of Interfaces.
    62  func (v *Var) Array() []interface{} {
    63  	return v.Interfaces()
    64  }
    65  
    66  // Vars converts and returns `v` as []Var.
    67  func (v *Var) Vars() []*Var {
    68  	array := gconv.Interfaces(v.Val())
    69  	if len(array) == 0 {
    70  		return nil
    71  	}
    72  	vars := make([]*Var, len(array))
    73  	for k, v := range array {
    74  		vars[k] = New(v)
    75  	}
    76  	return vars
    77  }