slice

package
v0.0.0-...-acb8ab4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2014 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Useful functions for handle slice. NOTE: function will panic if the argument type is not correct at runtime.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsList

func AsList(elements ...interface{}) *list.List

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

func FilterInt(elements []int, f func(int) bool) []int

Filter element satisfy function f, then return a new slice. If no element satisfied, return an empty slice.

func FilterString

func FilterString(elements []string, f func(string) bool) []string

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 FindInt

func FindInt(elements []int, f func(int) bool) (bool, int)

Find first element satisfy function f

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

func FindLastInt(elements []int, f func(int) bool) (bool, int)

Find first element satisfy function f in reverse order.

func FindLastString

func FindLastString(elements []string, f func(string) bool) (bool, string)

Find first element satisfy function f in reverse order.

func FindString

func FindString(elements []string, f func(string) bool) (bool, string)

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 Join

func Join(i interface{}, sep string) string

Join the slice elements string represention by sep.

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.

func ToList

func ToList(s interface{}) *list.List

Convert the slice elements to list. Panic if the argument type is not slice or slice pointer. Example: slice.ToList(&[]int{1, 2, 3, 5}), slice.ToList([]int{100, 2, 3, 5})

func ToSlice

func ToSlice(l *list.List) []interface{}

Convert the list elements to slice. Return empty slice ,if list if nil or empty;

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL