slice

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2021 License: MIT Imports: 1 Imported by: 0

README

Package slice

do something for a slice.

Usage

package main

import (
	"log"
	"strconv"
	"strings"

	"github.com/QisFj/godry/slice"
)

func main() {
	is := []int{1, 2, 3, 4, 5, 6}
	ss := slice.MapString(is, func(i int, v interface{}) string {
		return strconv.Itoa(v.(int))
	})
	log.Printf("after map: %#v\n", ss)
	slice.Filter(&ss, func(index int) bool {
		return strings.ContainsAny(ss[index], "135")
	})
	log.Printf("after filter: %#v\n", ss)
}

Map

Map a slice to another slice.

Filter

Filter some elements of slice.

Documentation

Overview

Code generated by go generate; DO NOT EDIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter

func Filter(slice interface{}, f func(index int) bool)

func Foreach

func Foreach(slice interface{}, f func(i int, v interface{}))

func KeysOfMap

func KeysOfMap(v interface{}) interface{}

convert a map to a key slice

func MapInt

func MapInt(slice interface{}, f IntMapFunc) []int

func MapInterface

func MapInterface(slice interface{}, f InterfaceMapFunc) []interface{}

func MapString

func MapString(slice interface{}, f StringMapFunc) []string

func MapT

func MapT(slice interface{}, t reflect.Type, f InterfaceMapFunc) interface{}

func MapUint

func MapUint(slice interface{}, f UintMapFunc) []uint

func Reduce

func Reduce(slice interface{}, initReduceValue interface{}, f func(reduceValue interface{}, i int, v interface{}) interface{}) (reduceValue interface{})

func ToMap

func ToMap(slice interface{},
	kt reflect.Type, getK func(i int, v interface{}) interface{},
	vt reflect.Type, getV func(i int, v interface{}) interface{},
) interface{}

convert a slice to a map kt, getK must not nil vt, getV can be nil value type would be interface{} when vt == nil value would be elem of slice when getV == nil

func ValuesOfMap

func ValuesOfMap(v interface{}) interface{}

convert a map to a value slice

Types

type IntMapFunc

type IntMapFunc func(i int, v interface{}) int

type InterfaceMapFunc

type InterfaceMapFunc func(i int, v interface{}) interface{}

type KV

type KV struct {
	Key   interface{}
	Value interface{}
}

func KVsOfMap

func KVsOfMap(v interface{}) []KV

convert a map to a kv slice so that other function in this package can be used

type StringMapFunc

type StringMapFunc func(i int, v interface{}) string

type UintMapFunc

type UintMapFunc func(i int, v interface{}) uint

Jump to

Keyboard shortcuts

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