slice

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: MIT Imports: 3 Imported by: 5

README

slice

go slice tools

sliceutil

golang sliceutil, including methods like TakeWhile, Filter, ForEach and so on, which were inpired by js slice similar: github.com/conbanwa/js

examples

package main

import (
	"github.com/conbanwa/slice"
)

func main() {
	println(slice.SubString(`1234567890`, 2))       //34567890
	println(slice.SubString(`1234567890`, -2))      //90
	println(slice.SubString(`1234567890`, 0, -4))   //123456
	println(slice.SubString(`1234567890`, 2, -4))   //3456
	println(slice.SubString(`1234567890`, 6, 99))   //7890
	println(slice.SubString(`1234567890`, -5, 4))   //empty
	println(slice.SubString(`1234567890`, -5, 99))  //67890
	println(slice.SubString(`1234567890`, -99, 99)) //1234567890

	println(slice.Slice([]byte(`1234567890`), 2))       //34567890
	println(slice.Slice([]byte(`1234567890`), -2))      //90
	println(slice.Slice([]byte(`1234567890`), 0, -4))   //123456
	println(slice.Slice([]byte(`1234567890`), 2, -4))   //3456
	println(slice.Slice([]byte(`1234567890`), 6, 99))   //7890
	println(slice.Slice([]byte(`1234567890`), -5, 4))   //empty
	println(slice.Slice([]byte(`1234567890`), -5, 99))  //67890
	println(slice.Slice([]byte(`1234567890`), -99, 99)) //1234567890
}

install

import github.com/conbanwa/slice

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BodyCut

func BodyCut(body []byte, max ...int) string

func BodySlice

func BodySlice(body []byte, limit ...int) string

func Bytes2String

func Bytes2String(b []byte) string

func Cut

func Cut[T comparable](arr []T, max ...int) []T

func MapKeys

func MapKeys[T comparable, V any](m map[T]V) []T

func Panic

func Panic(err error)

func Slice

func Slice[T comparable](arr []T, limit ...int) []T

Slice

start Optional Zero-based index at which to start extraction, converted to an integer.

Negative index counts back from the end of the array — if start < 0, start + array.length is used. If start < -array.length or start is omitted, 0 is used. If start >= array.length, nothing is extracted.

end Optional Zero-based index at which to end extraction, converted to an integer. slice() extracts up to but not including end.

Negative index counts back from the end of the array — if end < 0, end + array.length is used. If end < -array.length, 0 is used. If end >= array.length or end is omitted, array.length is used, causing all elements until the end to be extracted. If end is positioned before or at start after normalization, nothing is extracted.

func String2Bytes

func String2Bytes(b string) []byte

func ToMap

func ToMap[T comparable](sl []T) map[T]struct{}

func UniqSlice

func UniqSlice[T comparable](list []T) (x []T)

func ValuesToJson

func ValuesToJson(values url.Values) []byte

func ValuesToJsonSafe

func ValuesToJsonSafe(values url.Values) ([]byte, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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