Documentation
¶
Index ¶
- Variables
- type Object
- func (r *Object) Chunk(size int) *Object
- func (r *Object) Compact() *Object
- func (r *Object) EachArray(f func(idx int, obj interface{})) error
- func (r *Object) Error() error
- func (r *Object) FilterArray(f func(idx int, obj interface{}) bool) *Object
- func (r *Object) Flatten() *Object
- func (r *Object) GroupByArray(f func(idx int, obj interface{}) interface{}) *Object
- func (r *Object) IndexOf(obj interface{}) *Object
- func (r *Object) Join(sep string) (string, error)
- func (r *Object) MapArray(f func(idx int, obj interface{}) interface{}) *Object
- func (r *Object) MapArrayAsync(f func(idx int, obj interface{}) interface{}) *Object
- func (r *Object) MapArrayAsyncWithErr(f func(idx int, obj interface{}) (interface{}, error)) *Object
- func (r *Object) MapArrayWithErr(f func(idx int, obj interface{}) (interface{}, error)) *Object
- func (r *Object) Obj() (interface{}, error)
- func (r *Object) Reverse() *Object
- func (r *Object) String() (res string, err error)
- func (r *Object) ToBoolList() (res []bool, err error)
- func (r *Object) ToInt() (res int, err error)
- func (r *Object) ToIntList() (res []int, err error)
- func (r *Object) ToIntListList() (res [][]int, err error)
- func (r *Object) ToInterfaceList() (res []interface{}, err error)
- func (r *Object) ToList(resp interface{}) (err error)
- func (r *Object) ToMapInt2Float64List() (res map[int][]float64, err error)
- func (r *Object) ToStringList() (res []string, err error)
- func (r *Object) Transfer(f func(obj interface{}) interface{}) *Object
- func (r *Object) Uniq() *Object
- func (r *Object) WithErr(err error) *Object
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrBreak = fmt.Errorf("break range")
Functions ¶
This section is empty.
Types ¶
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
func New ¶
func New(obj interface{}) *Object
Example ¶
// new with string list lambda.New([]string{"1", "2"}) // new with struct lambda.New([]exampleItem{{Name: "Tom"}, {Name: "Harry"}})
func (*Object) Chunk ¶ added in v0.5.0
Example ¶
// Split the list into shorter length lists res, err := lambda.New([]int{1, 2, 3, 4, 5}).Chunk(2).ToIntListList() fmt.Println("err:", err) fmt.Println("res:", res)
Output: err: <nil> res: [[1 2] [3 4] [5]]
func (*Object) Compact ¶ added in v0.5.0
Example ¶
// Remove 0-valued elements from the list res, err := lambda.New([]int{0, 1, 2, 1, 0, 2}).Compact().ToIntList() fmt.Println("err:", err) fmt.Println("res:", res)
Output: err: <nil> res: [1 2 1 2]
func (*Object) FilterArray ¶ added in v0.5.0
Example ¶
// Traverse the elements of the list, each element is added to a new list or not, and a new list is returned res, err := lambda.New([]int{1, 2, 3, 4}).FilterArray(func(idx int, obj interface{}) bool { return obj.(int)%2 == 0 }).ToIntList() fmt.Println("err:", err) fmt.Println("res:", res)
Output: err: <nil> res: [2 4]
func (*Object) Flatten ¶ added in v0.4.0
Example ¶
// Flatten the list res, err := lambda.New([][]int{{1, 2}, {2, 3}, {4}}).Flatten().ToIntList() fmt.Println("err:", err) fmt.Println("res:", res)
Output: err: <nil> res: [1 2 2 3 4]
func (*Object) GroupByArray ¶ added in v0.5.0
func (*Object) MapArray ¶ added in v0.5.0
Example ¶
// Traverse the elements of the list, and after each element is processed, the returned elements form a new list res, err := lambda.New([]int{1, 2, 3}).MapArray(func(idx int, obj interface{}) interface{} { return obj.(int) + 1 }).ToIntList() fmt.Println("err:", err) fmt.Println("res:", res)
Output: err: <nil> res: [2 3 4]
func (*Object) MapArrayAsync ¶ added in v0.6.0
func (*Object) MapArrayAsyncWithErr ¶ added in v0.6.0
func (*Object) MapArrayWithErr ¶ added in v0.6.0
func (*Object) Reverse ¶ added in v0.5.0
Example ¶
// Reverse list res, err := lambda.New([]int{1, 2, 3, 4}).Reverse().ToIntList() fmt.Println("err:", err) fmt.Println("res:", res)
Output: err: <nil> res: [4 3 2 1]
func (*Object) ToBoolList ¶ added in v0.5.0
func (*Object) ToIntListList ¶ added in v0.5.0
func (*Object) ToInterfaceList ¶ added in v0.5.0
func (*Object) ToMapInt2Float64List ¶ added in v0.5.0
func (*Object) ToStringList ¶ added in v0.5.0
Source Files
¶
Click to show internal directories.
Click to hide internal directories.