Documentation ¶
Overview ¶
Useful functions for handle slice. NOTE: function will panic if the argument type is not correct at runtime.
Index ¶
- func AsList(elements ...interface{}) *list.List
- func Exist(i interface{}, f interface{}) bool
- func Filter(i interface{}, f interface{}) []interface{}
- func FilterInt(elements []int, f func(int) bool) []int
- func FilterString(elements []string, f func(string) bool) []string
- func Find(i interface{}, f interface{}) (bool, interface{})
- func FindInt(elements []int, f func(int) bool) (bool, int)
- func FindLast(i interface{}, f interface{}) (bool, interface{})
- func FindLastInt(elements []int, f func(int) bool) (bool, int)
- func FindLastString(elements []string, f func(string) bool) (bool, string)
- func FindString(elements []string, f func(string) bool) (bool, string)
- func Foreach(i interface{}, f interface{})
- func Index(i interface{}, f interface{}) int
- func IndexLast(i interface{}, f interface{}) int
- func Join(i interface{}, sep string) string
- func Map(i interface{}, f interface{}) []interface{}
- func MapFilter(i interface{}, f interface{}) []interface{}
- func MapFilterInt(i interface{}, f interface{}) []int64
- func MapFilterString(i interface{}, f interface{}) []string
- func MapInt(i interface{}, f interface{}) []int64
- func MapString(i interface{}, f interface{}) []string
- func ToList(s interface{}) *list.List
- func ToSlice(l *list.List) []interface{}
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsList ¶
New a list, and append the elements to list in order. Example: slice.AsList(1, 2, "3", "Hello, GoLang")
func Exist ¶
func Exist(i interface{}, f interface{}) bool
Check if the slice has element satisfy function f. NOTE: Panic if i is not slice or slice pointer, f type is not func or func pointer. Return true if slice has at least such one element, Otherwise false.
func Filter ¶
func Filter(i interface{}, f interface{}) []interface{}
Filter element satisfy function f, then return a new slice. NOTE: Panic if i is not slice or slice pointer, f type is not func or func pointer. If no element satisfied, return an empty slice.
func FilterInt ¶
Filter element satisfy function f, then return a new slice. If no element satisfied, return an empty slice.
func FilterString ¶
Filter element satisfy function f, then return a new slice. If no element satisfied, return an empty slice.
func Find ¶
func Find(i interface{}, f interface{}) (bool, interface{})
Find first element satisfy function f NOTE: Panic if i is not slice or slice pointer, f type is not func or func pointer.
func FindLast ¶
func FindLast(i interface{}, f interface{}) (bool, interface{})
Find first element satisfy function f in reverse order. NOTE: Panic if i is not slice or slice pointer, f type is not func or func pointer.
func FindLastInt ¶
Find first element satisfy function f in reverse order.
func FindLastString ¶
Find first element satisfy function f in reverse order.
func FindString ¶
Find first element satisfy function f
func Foreach ¶
func Foreach(i interface{}, f interface{})
Traverse the slice, call function f by element in order. NOTE: Panic if i is not slice or slice pointer, f type is not func or func pointer.
func Index ¶
func Index(i interface{}, f interface{}) int
Get first element index satisfy function f NOTE: Panic if i is not slice or slice pointer, f type is not func or func pointer. Return -1, if no element satisfy.
func IndexLast ¶
func IndexLast(i interface{}, f interface{}) int
Get first element index satisfy function f in reverse order. NOTE: Panic if i is not slice or slice pointer, f type is not func or func pointer. Return -1, if no element satisfy.
func Map ¶
func Map(i interface{}, f interface{}) []interface{}
Map the slice to another slice, convert element by function f in order. NOTE: Panic if i is not slice or slice pointer, f type is not func or func pointer.
func MapFilter ¶
func MapFilter(i interface{}, f interface{}) []interface{}
Map and filter the slice to another slice, convert element by function f in order. NOTE: Panic if i is not slice or slice pointer, f type is not func or func pointer.
func MapFilterInt ¶
func MapFilterInt(i interface{}, f interface{}) []int64
Map and filter the slice to another int slice, convert element by function f in order.
func MapFilterString ¶
func MapFilterString(i interface{}, f interface{}) []string
Map and filter slice to another string slice, convert element by function f in order.
func MapInt ¶
func MapInt(i interface{}, f interface{}) []int64
Map the slice to another int slice, convert element by function f in order.
func MapString ¶
func MapString(i interface{}, f interface{}) []string
Map slice to another string slice, convert element by function f in order.
Types ¶
This section is empty.