stl

package
v1.1.25 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const MinRead = 512

MinRead 与 bytes.Buffer 一致:ReadFrom 单次至少向 r 预留这么多容量,减少扩容次数。

Variables

View Source
var ErrTooLarge = errors.New("stl.Buffer: too large")

ErrTooLarge 在无法为缓冲区分配足够内存时由 grow 触发 panic 的值(与 bytes.Buffer 语义一致)。

View Source
var (
	NopLogger = zap.NewNop()
)

Functions

func AlignCeil added in v1.1.3

func AlignCeil[Int constraints.Integer](value Int, base Int) Int

func AlignFloor added in v1.1.3

func AlignFloor[Int constraints.Integer](value Int, base Int) Int

func AllEqual added in v1.0.77

func AllEqual[Datas ~[]Data, Data comparable](datas Datas, value Data) bool

func AllMatch

func AllMatch[Data any](datas []Data, test func(Data) bool) bool

func AllMatchPro added in v1.0.3

func AllMatchPro[Data any, Datas ~[]Data](datas Datas, test func(int, Data, Datas) bool) bool

func AnyMatch

func AnyMatch[Data any](datas []Data, test func(Data) bool) bool

func AnyMatchPro added in v1.0.3

func AnyMatchPro[Data any, Datas ~[]Data](datas Datas, test func(int, Data, Datas) bool) bool

func Avg added in v1.1.8

func Avg[
	Datas ~[]Data,
	Data Number,
](datas Datas) Data

func Backmost added in v1.0.32

func Backmost[Datas ~[]Data, Data any](datas Datas, before func(a, b Data) bool) (result Data, index int)

func BackmostPro added in v1.0.32

func BackmostPro[Datas ~[]Data, Data any](datas Datas, before func(a, b Data) bool) (result Data, index int)

func BatchAssertType added in v1.0.61

func BatchAssertType[Dst any, Source any, Sources ~[]Source](sources Sources) ([]Dst, bool)

func BatchDeleteMap

func BatchDeleteMap[Key comparable, Keys ~[]Key, Value any, Map ~map[Key]Value](m Map, keys Keys) Map

func BatchDeleteMapFromAnother

func BatchDeleteMapFromAnother[Key comparable, Value any, Map ~map[Key]Value](m Map, keys Map) Map

func BatchProcessUntilFirstError added in v1.0.44

func BatchProcessUntilFirstError[Data any, Datas ~[]Data](datas Datas, f func(Data) error) error

func BatchProcessUntilFirstErrorX added in v1.0.90

func BatchProcessUntilFirstErrorX[Data any](f func(Data) error, datas ...Data) error

func Bisect added in v1.0.63

func Bisect[Datas ~[]Data, Data any](datas Datas, tester func(Data) bool) (trues Datas, falses Datas)

func BisectByKeyAmbiguity added in v1.0.63

func BisectByKeyAmbiguity[Datas ~[]Data, Data any, Key comparable](datas Datas, key func(Data) Key) (unambiguous, ambiguous Datas)

func BuildMap added in v1.0.18

func BuildMap[Map ~map[Key]Value, Datas ~[]Data, Key comparable, Value any, Data any](datas Datas, kv func(data Data) (Key, Value)) Map

func BuildMapPro added in v1.0.18

func BuildMapPro[Map ~map[Key]Value, Datas ~[]Data, Key comparable, Value any, Data any](datas Datas, kv func(data Data) (Key, Value, bool, error)) (Map, error)

func CacheMapValue added in v1.0.8

func CacheMapValue[Key comparable, Value any, Map ~map[Key]Value](m Map, key Key, value Value) Value

func CacheMapValueWithInitializer added in v1.0.8

func CacheMapValueWithInitializer[Key comparable, Value any, Map ~map[Key]Value](m Map, key Key, initializer func() Value) Value

func ChainUnaryHandler added in v1.0.46

func ChainUnaryHandler[
	Data any,
	Arg any,
](handler func(*Data, Arg)) func(*Data, Arg) *Data

func Close added in v1.1.8

func Close(x any) error

✅ 关闭一个对象 stl需要调用,因此不能放在std/iox包中

func CloseQuietly added in v1.1.8

func CloseQuietly(x any)

func Compare added in v1.0.8

func Compare[Data constraints.Ordered](as []Data, bs []Data) int

func ConcatMap

func ConcatMap[Key comparable, Value any, Map ~map[Key]Value](dst, src Map) Map

func ConcatMapInplace

func ConcatMapInplace[Map ~map[Key]Value, Key comparable, Value any](dst, src Map) Map

func ConcatMaps added in v1.0.40

func ConcatMaps[Map ~map[Key]Value, Key comparable, Value any](maps ...Map) Map

func ConcatMapsTo added in v1.0.40

func ConcatMapsTo[Map ~map[Key]Value, Key comparable, Value any](dst Map, maps ...Map) Map

func ConcatSlices

func ConcatSlices[Slice ~[]Data, Data any](slices ...Slice) Slice

func ConcatSlicesTo

func ConcatSlicesTo[Data any, Slice ~[]Data](slice Slice, slices ...Slice) Slice

func Contain added in v1.0.47

func Contain[Datas ~[]Data, Data comparable](datas Datas, target Data) bool

func ContainAll added in v1.0.61

func ContainAll[Datas ~[]Data, Data comparable](datas Datas, targets ...Data) bool

func ContainAny added in v1.0.61

func ContainAny[Datas ~[]Data, Data comparable](datas Datas, targets ...Data) bool

func CountAndMap added in v1.0.44

func CountAndMap[
	Number interface {
		constraints.Integer | constraints.Float
	},
	Mapper func(Number) Data,
	Data any,
](start, end, step Number, mapper Mapper) []Data

func CountAndMapLite added in v1.0.44

func CountAndMapLite[
	Number interface {
		constraints.Integer | constraints.Float
	},
	Mapper func() Data,
	Data any,
](start, end, step Number, mapper Mapper) []Data

func CountAndMapPro added in v1.0.44

func CountAndMapPro[
	Number interface {
		constraints.Integer | constraints.Float
	},
	Mapper func(Number, []Data) Data,
	Data any,
](start, end, step Number, mapper Mapper) []Data

func DataSeq added in v1.1.6

func DataSeq[Data any](datas ...Data) iter.Seq[Data]

func Dereference added in v1.0.35

func Dereference[Ptr ~*Data, Data any](ptr Ptr) Data

func Divide added in v1.0.33

func Divide[Datas ~[]Data, Data any](datas Datas, size int, dup bool) (subs []Datas)

func Dup added in v1.0.7

func Dup[Data any, Ptr ~*Data](ptr Ptr) Ptr

func DupMap

func DupMap[Key comparable, Value any, Map ~map[Key]Value](m Map) Map

func DupSlice

func DupSlice[Data any, Slice ~[]Data](slice Slice) Slice

func Echo added in v1.0.35

func Echo[Data any](data Data) Data

func Echoer added in v1.0.77

func Echoer[T any](data T) func() T

func EmptySeq added in v1.1.6

func EmptySeq[Data any](yield func(Data) bool)

func EmptySeq2 added in v1.1.6

func EmptySeq2[K any, V any](yield func(K, V) bool)

func EqualBySet added in v1.0.8

func EqualBySet[Data comparable](as []Data, bs []Data) bool

func EqualBySort added in v1.0.8

func EqualBySort[Data constraints.Ordered](as []Data, bs []Data) bool

func FillSliceToCap added in v1.0.8

func FillSliceToCap[Data any, Datas ~[]Data](datas Datas, g func(int) Data) Datas

func Filter

func Filter[Data any, Datas ~[]Data](datas Datas, filter func(Data) bool) Datas

func FilterByKey added in v1.0.77

func FilterByKey[Datas ~[]Data, Data any, Key comparable](datas Datas, keyFunc func(Data) Key, key Key) Datas

func FilterByKeySet added in v1.0.68

func FilterByKeySet[Datas ~[]Data, Data any, Key comparable](datas Datas, dataKey func(Data) Key, keySet Set[Key]) Datas

func FilterByKeys added in v1.0.67

func FilterByKeys[Datas ~[]Data, Data any, Key comparable](datas Datas, dataKey func(Data) Key, keys ...Key) Datas

func FilterMap added in v1.0.28

func FilterMap[Map ~map[Key]Value, Key comparable, Value any](m Map, tester func(Key, Value, Map) bool) Map

func FilterMapByKey added in v1.0.61

func FilterMapByKey[Map ~map[Key]Value, Key comparable, Value any](m Map, f func(Key) bool) Map

func FilterMapByValue added in v1.0.61

func FilterMapByValue[Map ~map[Key]Value, Key comparable, Value any](m Map, f func(Value) bool) Map

func FilterPro added in v1.0.3

func FilterPro[Data any, Datas ~[]Data](datas Datas, filter func(int, Data, Datas) bool) Datas

func FilterZeroKey added in v1.0.63

func FilterZeroKey[Datas ~[]Data, Data any, Key comparable](datas Datas, key func(Data) Key) Datas

func FindFirst added in v1.0.23

func FindFirst[Datas ~[]Data, Data any](datas Datas, test func(Data) bool) (Data, bool)

func FindFirstByKey added in v1.0.67

func FindFirstByKey[Datas ~[]Data, Key comparable, Data any](datas Datas, keyFunc func(Data) Key, key Key) (result Data, ok bool)

func FindFirstNotZero added in v1.0.26

func FindFirstNotZero[Data comparable](datas []Data) Data

func FindFirstOrDefault added in v1.0.23

func FindFirstOrDefault[Data any](datas []Data, test func(Data) bool, defaultData Data) Data

func FindFirstOrDefaultByKey added in v1.0.67

func FindFirstOrDefaultByKey[Datas ~[]Data, Key comparable, Data any](datas Datas, keyFunc func(Data) Key, key Key, default_ Data) Data

func FindFirstOrZero added in v1.0.23

func FindFirstOrZero[Data any](datas []Data, test func(Data) bool) Data

func FindFirstOrZeroByKey added in v1.0.67

func FindFirstOrZeroByKey[Datas ~[]Data, Key comparable, Data any](datas Datas, keyFunc func(Data) Key, key Key) Data

func FindLast added in v1.0.22

func FindLast[Datas ~[]Data, Data any](datas Datas, test func(Data) bool) (Data, bool)

func FindLastOrDefault added in v1.0.22

func FindLastOrDefault[Data any](datas []Data, test func(Data) bool, defaultData Data) Data

func FindLastOrZero added in v1.0.22

func FindLastOrZero[Data any](datas []Data, test func(Data) bool) Data

func FirstNotZeroKey added in v1.1.22

func FirstNotZeroKey[Datas ~[]Data, Data any, Key comparable](datas Datas, keyFunc func(Data) Key) Key

func FirstOneOrZero added in v1.0.26

func FirstOneOrZero[Datas ~[]Data, Data any](datas Datas) (data Data)

func ForEach

func ForEach[Data any](datas []Data, handler func(data Data))

func ForEachBinary added in v1.1.7

func ForEachBinary[
	Datas ~[]Data,
	Data any,
	Arg1 any,
	Arg2 any,
](datas Datas, handler func(Data, Arg1, Arg2), arg1 Arg1, arg2 Arg2)

func ForEachBinaryByMapper added in v1.1.7

func ForEachBinaryByMapper[
	Datas ~[]Data,
	Data any,
	Arg1 any,
	Arg2 any,
	Result any,
](datas Datas, mapper func(Data, Arg1, Arg2) Result, arg1 Arg1, arg2 Arg2)

func ForEachByMapper added in v1.0.55

func ForEachByMapper[Data any, Result any](datas []Data, mapper func(data Data) Result)

func ForEachPro added in v1.0.3

func ForEachPro[Data any, Datas ~[]Data](datas Datas, handler func(i int, data Data, datas Datas))

func ForEachTernary added in v1.1.7

func ForEachTernary[
	Datas ~[]Data,
	Data any,
	Arg1 any,
	Arg2 any,
	Arg3 any,
](datas Datas, handler func(Data, Arg1, Arg2, Arg3), arg1 Arg1, arg2 Arg2, arg3 Arg3)

func ForEachTernaryByMapper added in v1.1.7

func ForEachTernaryByMapper[
	Datas ~[]Data,
	Data any,
	Arg1 any,
	Arg2 any,
	Arg3 any,
	Result any,
](datas Datas, mapper func(Data, Arg1, Arg2, Arg3) Result, arg1 Arg1, arg2 Arg2, arg3 Arg3)

func ForEachUnary added in v1.1.7

func ForEachUnary[
	Datas ~[]Data,
	Data any,
	Arg any,
](datas Datas, handler func(Data, Arg), arg Arg)

func ForEachUnaryByMapper added in v1.1.7

func ForEachUnaryByMapper[
	Datas ~[]Data,
	Data any,
	Arg any,
	Result any,
](datas Datas, mapper func(Data, Arg) Result, arg Arg)

func GetCachedDataFetchLite added in v1.1.7

func GetCachedDataFetchLite[
	Func ~func(context.Context) (Data, error),
	Data any,
](cachedFetcher *CachedDataFetcher[Data]) Func

func GetContextValue added in v1.0.56

func GetContextValue[Value any, Key any](ctx context.Context, key Key) (value Value)

func GetSliceElemPointers

func GetSliceElemPointers[Data any, Datas ~[]Data](datas Datas) []*Data

func Greater added in v1.1.8

func Greater[Data constraints.Ordered](a, b Data) bool

func Headmost added in v1.0.32

func Headmost[Datas ~[]Data, Data any](datas Datas, before func(a, b Data) bool) (result Data)

func HeadmostPro added in v1.0.32

func HeadmostPro[Datas ~[]Data, Data any](datas Datas, before func(a, b Data) bool) (result Data, index int)

func Index added in v1.0.17

func Index[Data any](datas []Data, i int) (data Data, ok bool)

func IndexDataSeq added in v1.1.6

func IndexDataSeq[Data any](datas ...Data) iter.Seq2[int, Data]

func IndexOf

func IndexOf[Data comparable](datas []Data, target Data) int

func IndexOfKey added in v1.1.22

func IndexOfKey[Datas ~[]Data, Data any, Key comparable](datas Datas, key func(Data) Key, target Key) int

func InstancesToPointers

func InstancesToPointers[Data any, Instances ~[]Data](instances Instances) []*Data

func IsNegativeNumber added in v1.1.8

func IsNegativeNumber[Data Number](number Data) bool

func IsPositiveNumber added in v1.1.8

func IsPositiveNumber[Data Number](number Data) bool

func JoinSlices added in v1.0.26

func JoinSlices[Slice ~[]Data, Data any](sep Slice, slices ...Slice) Slice

func JoinSlicesTo added in v1.0.26

func JoinSlicesTo[Slice ~[]Data, Data any](slice Slice, sep Slice, keepFirstSep bool, slices ...Slice) Slice

func LastOneOrZero added in v1.0.31

func LastOneOrZero[Datas ~[]Data, Data any](datas Datas) (data Data)

func Less added in v1.1.8

func Less[Data constraints.Ordered](a, b Data) bool

func LookupContextValue added in v1.0.56

func LookupContextValue[Value any, Key any](ctx context.Context, key Key) (value Value, ok bool)

func Map

func Map[Datas ~[]Data, Result any, Data any](datas Datas, mapper func(Data) Result) []Result

✅ 映射

func MapAndConcat

func MapAndConcat[Data any, Datas ~[]Data, Result any, Results ~[]Result](datas Datas, mapper func(Data) Results) Results

func MapAndConcatWithError added in v1.0.26

func MapAndConcatWithError[Datas ~[]Data, Results ~[]Result, Data any, Result any](datas Datas, stopWhenError bool, mapper func(Data) (Results, error)) (Results, error)

func MapAndJoinWithError added in v1.0.26

func MapAndJoinWithError[Datas ~[]Data, Results ~[]Result, Data any, Result any](datas Datas, sep Results, stopWhenError bool, mapper func(Data) (Results, error)) (Results, error)

func MapArgs

func MapArgs[Data any, Result any](mapper func(Data) Result, args ...Data) []Result

func MapBinary added in v1.1.7

func MapBinary[
	Datas ~[]Data,
	Data any,
	Arg1 any,
	Arg2 any,
	Result any,
](datas Datas, mapper func(Data, Arg1, Arg2) Result, arg1 Arg1, arg2 Arg2) []Result

✅ 带两个参数的映射

func MapIterator added in v1.0.35

func MapIterator[Data any, Result any](it Iterator[Data], mapper func(Data) Result) []Result

func MapKeys

func MapKeys[Map ~map[Key]Value, Key comparable, Value any](m Map) []Key

func MapMap added in v1.0.27

func MapMap[DstMap ~map[DstKey]DstValue, DstKey comparable, DstValue any, SrcMap ~map[SrcKey]SrvValue, SrcKey comparable, SrvValue any](m SrcMap, mapper func(SrcKey, SrvValue, SrcMap) (DstKey, DstValue)) DstMap

func MapMapLite added in v1.0.44

func MapMapLite[Map ~map[Key]Value, Key comparable, Value any](m Map, mapper func(Key, Value, Map) (Key, Value)) Map

func MapMapPro added in v1.0.53

func MapMapPro[DM ~map[DK]DV, SM ~map[SK]SV, SK comparable, SV any, DK comparable, DV any](sm SM, mapper func(sk SK, sv SV, sm SM, dm DM) (DK, DV, bool, error)) (DM, bool, error)

func MapMapToSlice added in v1.0.27

func MapMapToSlice[Slice ~[]SliceItem, Map ~map[Key]Value, SliceItem any, Key comparable, Value any](m Map, convert func(Key, Value, Map) SliceItem) Slice

func MapMapToSlicePro added in v1.0.27

func MapMapToSlicePro[Slice ~[]SliceItem, Map ~map[Key]Value, SliceItem any, Key comparable, Value any](m Map, convert func(Key, Value, Map) (SliceItem, bool, error)) (Slice, error)

func MapPro added in v1.0.3

func MapPro[Data any, Datas ~[]Data, Result any](datas Datas, mapper func(int, Data, Datas) Result) []Result

func MapProArgs added in v1.0.3

func MapProArgs[Data any, Datas ~[]Data, Result any](mapper func(int, Data, Datas) Result, datas ...Data) []Result

func MapSeq added in v1.0.95

func MapSeq[Data any, Result any](seq iter.Seq[Data], mapper func(Data) Result) []Result

func MapTernary added in v1.1.7

func MapTernary[
	Datas ~[]Data,
	Data any,
	Arg1 any,
	Arg2 any,
	Arg3 any,
	Result any,
](datas Datas, mapper func(Data, Arg1, Arg2, Arg3) Result, arg1 Arg1, arg2 Arg2, arg3 Arg3) []Result

✅ 带三个参数的映射

func MapToAssertedType added in v1.0.61

func MapToAssertedType[Dst any, Source any, Sources ~[]Source](sources Sources) (result []Dst)

func MapUnary added in v1.1.7

func MapUnary[
	Datas ~[]Data,
	Data any,
	Arg any,
	Result any,
](datas Datas, mapper func(Data, Arg) Result, arg Arg) []Result

✅ 带一个参数的映射

func MapUntilError added in v1.0.95

func MapUntilError[Datas ~[]Data, Result any, Data any](datas Datas, mapper func(Data) (Result, error)) ([]Result, error)

func MapValueGetter added in v1.0.17

func MapValueGetter[Key comparable, Value any, Map ~map[Key]Value](m Map) func(Key) Value

func MapValueGetterPro added in v1.0.17

func MapValueGetterPro[Key comparable, Value any, Map ~map[Key]Value](m Map, keys ...Key) func(Key) (Value, bool)

func MapValues added in v1.0.6

func MapValues[Key comparable, Value any, Map ~map[Key]Value](m Map) []Value

func MapValuesByKeys added in v1.0.6

func MapValuesByKeys[Key comparable, Value any, Map ~map[Key]Value](m Map, keys ...Key) []Value

func MapWithErrorSimplified added in v1.0.77

func MapWithErrorSimplified[Datas ~[]Data, Result any, Data any](datas Datas, mapper func(Data) (Result, error)) ([]Result, error)

func MappingByKey

func MappingByKey[Data any, Datas ~[]Data, Key comparable](datas Datas, key func(Data) Key) map[Key]Data

func MappingByKeyPro added in v1.0.3

func MappingByKeyPro[Data any, Datas ~[]Data, Key comparable](datas Datas, key func(int, Data, Datas) Key) map[Key]Data

func MappingByKeys

func MappingByKeys[Data any, Datas ~[]Data, Key comparable, Keys ~[]Key](datas Datas, keys func(Data) Keys) map[Key]Data

func Max added in v1.0.19

func Max[Datas ~[]Data, Data constraints.Ordered](datas Datas, _default Data) (result Data)

func Min added in v1.0.19

func Min[Datas ~[]Data, Data constraints.Ordered](datas Datas, _default Data) (result Data)

func MultiSeq added in v1.1.6

func MultiSeq[Data any](seqs ...iter.Seq[Data]) iter.Seq[Data]

func MultiSeq2 added in v1.1.6

func MultiSeq2[K any, V any](seqs ...iter.Seq2[K, V]) iter.Seq2[K, V]

func MultivalueMap added in v1.0.43

func MultivalueMap[Result ~map[Key]Values, Values ~[]Value, Map ~map[Key]Value, Key comparable, Value any](m Map) Result

func MustLookupContextValue added in v1.0.56

func MustLookupContextValue[Value any, Key any](ctx context.Context, key Key) (value Value)

func New added in v1.0.40

func New[Data any]() (data Data)

func NewAsAny added in v1.0.68

func NewAsAny[T any]() any

func NewChanFromDatasX added in v1.0.78

func NewChanFromDatasX[DataChan ~chan Data, Data any](datas ...Data) DataChan

func NewFirstWriteBuffer added in v1.1.18

func NewFirstWriteBuffer[Datas ~[]Data, Data any]() *reduceWriteBuffer[Datas, Data, Data]

func NewLastWriteBuffer added in v1.1.18

func NewLastWriteBuffer[Datas ~[]Data, Data any]() *reduceWriteBuffer[Datas, Data, Data]

func NewPtr added in v1.0.40

func NewPtr[Ptr ~*Data, Data any]() Ptr

func NewReduceWriteBuffer added in v1.1.18

func NewReduceWriteBuffer[Datas ~[]Data, Data any, Result any](reduce func(result Result, data Data) Result) *reduceWriteBuffer[Datas, Data, Result]

func NotGreater added in v1.1.8

func NotGreater[Data constraints.Ordered](a, b Data) bool

func NotLess added in v1.1.8

func NotLess[Data constraints.Ordered](a, b Data) bool

func NotNilSlice added in v1.1.7

func NotNilSlice[Datas ~[]Data, Data any](datas Datas) Datas

func PopMap

func PopMap[Key comparable, Value any, Map ~map[Key]Value](m Map, key Key) (value Value, ok bool)

func Purge

func Purge[Datas ~[]Data, Data any](datas Datas, filter func(Data) bool) Datas

func PurgeMapKeys added in v1.0.47

func PurgeMapKeys[Map ~map[Key]Value, Key comparable, Value any](m Map, keys ...Key) Map

func PurgeMapZeroKey added in v1.0.47

func PurgeMapZeroKey[Map ~map[Key]Value, Key comparable, Value any](m Map) Map

func PurgeValue

func PurgeValue[Datas ~[]Data, Data comparable](datas Datas, value Data) Datas

func PurgeZero

func PurgeZero[Datas ~[]Data, Data comparable](datas Datas) Datas

func PurgeZeroKey added in v1.0.58

func PurgeZeroKey[Datas ~[]Data, Data any, Key comparable](datas Datas, key func(Data) Key) Datas

func PushDataToChanX added in v1.0.78

func PushDataToChanX[DataChan ~chan Data, Data any](dataChan DataChan, datas ...Data) DataChan

func RandomOneOrZero added in v1.0.90

func RandomOneOrZero[Datas ~[]Data, Data any](datas Datas, rand_ *rand.Rand) (data Data)

func ReadAll added in v1.0.77

func ReadAll[Datas ~[]Data, Data any](read func() (Data, error)) (Datas, error)

func ReadChan added in v1.0.8

func ReadChan[Data any](c chan Data, n int) []Data

func ReadChanAll added in v1.0.8

func ReadChanAll[Data any, Datas ~[]Data](c chan Data) (datas Datas)

func Reduce

func Reduce[Data any, Datas ~[]Data, Result any](datas Datas, reducer func(Result, Data) Result, initial Result) (result Result)

func ReducePro added in v1.0.3

func ReducePro[Data any, Datas ~[]Data, Result any](datas Datas, reducer func(Result, Data, int, Datas) Result, initial Result) (result Result)

func Reference added in v1.0.35

func Reference[Data any](data Data) *Data

func ReflectType added in v1.0.48

func ReflectType[T any]() reflect.Type

func Reverse added in v1.0.61

func Reverse[Datas ~[]Data, Data any](datas Datas) Datas

func SeqDataErrorFromReader added in v1.1.6

func SeqDataErrorFromReader[Datas ~[]Data, Data any](r Reader[Datas, Data]) iter.Seq2[Data, error]

func SeqFromReader added in v1.1.6

func SeqFromReader[Datas ~[]Data, Data any](r Reader[Datas, Data]) iter.Seq[Data]

func SetZero added in v1.1.23

func SetZero[Ptr ~*Data, Data any](ptr Ptr) Ptr

func Shuffle added in v1.0.88

func Shuffle[Datas ~[]Data, Data any](datas Datas, rand_ *rand.Rand) Datas

func SingularDataSeq added in v1.1.6

func SingularDataSeq[Data any](data Data) iter.Seq[Data]

func SingularIndexDataSeq added in v1.1.6

func SingularIndexDataSeq[Data any](index int, data Data) iter.Seq2[int, Data]

func SingularKeyValueSeq added in v1.1.7

func SingularKeyValueSeq[K any, V any](key K, value V) iter.Seq2[K, V]

func SliceEmpty added in v1.0.55

func SliceEmpty[Datas ~[]Data, Data any](datas Datas) bool

func SliceEqual added in v1.0.11

func SliceEqual[Datas ~[]Data, Data comparable](as Datas, bs Datas) bool

func SliceLen added in v1.0.55

func SliceLen[Datas ~[]Data, Data any](datas Datas) int

func SliceMappingByKey

func SliceMappingByKey[Data any, Datas ~[]Data, Key comparable](datas Datas, key func(Data) Key) map[Key]Datas

func SliceMappingByKeys

func SliceMappingByKeys[Data any, Datas ~[]Data, Key comparable, Keys ~[]Key](datas Datas, keys func(Data) Keys) map[Key]Datas

func SliceNil added in v1.0.55

func SliceNil[Datas ~[]Data, Data any](datas Datas) bool

func Sort

func Sort[Data any, Datas ~[]Data](datas Datas, less func(a, b Data) bool) Datas

func SortByKey added in v1.0.88

func SortByKey[Datas ~[]Data, Data any, Key constraints.Ordered](datas Datas, key func(Data) Key, desc bool) Datas

func SortByKeyAsc added in v1.0.88

func SortByKeyAsc[Datas ~[]Data, Data any, Key constraints.Ordered](datas Datas, key func(Data) Key) Datas

func SortByKeyDesc added in v1.0.88

func SortByKeyDesc[Datas ~[]Data, Data any, Key constraints.Ordered](datas Datas, key func(Data) Key) Datas

func SortFast

func SortFast[Data constraints.Ordered, Datas ~[]Data](datas Datas) Datas

func SortUniqueFast

func SortUniqueFast[Data constraints.Ordered, Datas ~[]Data](datas Datas) Datas

func StableUniqueBySet added in v1.0.65

func StableUniqueBySet[Datas ~[]Data, Data comparable](datas Datas) Datas

func SubMapByKeys added in v1.0.17

func SubMapByKeys[Key comparable, Value any, Map ~map[Key]Value](m Map, keys ...Key) Map

func Sum added in v1.0.19

func Sum[Datas ~[]Data, Data Addend](datas Datas, start Data) Data

func ToTypeless added in v1.0.35

func ToTypeless[Data any](data Data) any

func ToTypelessSlice added in v1.0.35

func ToTypelessSlice[Datas ~[]Data, Data any](datas Datas) []any

func TypeAsserter added in v1.0.61

func TypeAsserter[Dst any, Src any](src Src) (dst Dst, ok bool)

func UnchainUnaryHandler added in v1.0.46

func UnchainUnaryHandler[
	Data any,
	Arg any,
](handler func(Data, Arg) Data) func(Data, Arg)

func Unique

func Unique[Data comparable, Datas ~[]Data](datas Datas, equal func(Data, Data) bool) Datas

func UniqueByKeySet added in v1.0.11

func UniqueByKeySet[Datas ~[]Data, Data any, Key comparable](datas Datas, key func(Data) Key) Datas

func UniqueBySet

func UniqueBySet[Data comparable, Datas ~[]Data](datas Datas) Datas

func UniqueSorteds added in v1.0.11

func UniqueSorteds[Data comparable, Datas ~[]Data](datas Datas) Datas

func UnmarshalJson added in v1.0.77

func UnmarshalJson[T any](raw []byte) (result T, err error)

func WriteSeq added in v1.1.6

func WriteSeq[Datas ~[]Data, Data any](dst Writer[Datas, Data], seq iter.Seq[Data]) (int64, error)

func WriteSeq2DataError added in v1.1.8

func WriteSeq2DataError[Datas ~[]Data, Data any](dst Writer[Datas, Data], seq iter.Seq2[Data, error]) (int64, error)

func WriteSeq2Key added in v1.1.8

func WriteSeq2Key[Datas ~[]Data, Data any](dst Writer[Datas, Data], seq iter.Seq2[Data, any]) (int64, error)

func WriteSeq2Value added in v1.1.8

func WriteSeq2Value[Datas ~[]Data, Data any](dst Writer[Datas, Data], seq iter.Seq2[any, Data]) (int64, error)

func Zero added in v1.0.69

func Zero[Data any]() (_ Data)

Types

type Added added in v1.1.8

type Added = Number

type Addend added in v1.0.19

type Addend interface {
	constraints.Integer | constraints.Float
}

type BoundedBuffer added in v1.0.95

type BoundedBuffer[Datas ~[]Data, Data any] struct {
	// contains filtered or unexported fields
}

func NewBoundedBuffer added in v1.0.95

func NewBoundedBuffer[Datas ~[]Data, Data any](size int) *BoundedBuffer[Datas, Data]

func (*BoundedBuffer[Datas, Data]) Datas added in v1.0.95

func (lb *BoundedBuffer[Datas, Data]) Datas() Datas

func (*BoundedBuffer[Datas, Data]) IsFull added in v1.0.95

func (lb *BoundedBuffer[Datas, Data]) IsFull() bool

func (*BoundedBuffer[Datas, Data]) IsTruncated added in v1.0.95

func (lb *BoundedBuffer[Datas, Data]) IsTruncated() bool

func (*BoundedBuffer[Datas, Data]) Reset added in v1.0.95

func (lb *BoundedBuffer[Datas, Data]) Reset()

func (*BoundedBuffer[Datas, Data]) TotalWritten added in v1.0.95

func (lb *BoundedBuffer[Datas, Data]) TotalWritten() int64

func (*BoundedBuffer[Datas, Data]) Write added in v1.0.95

func (lb *BoundedBuffer[Datas, Data]) Write(datas Datas) (n int, err error)

type Buffer added in v1.1.1

type Buffer[Datas ~[]Data, Data any] struct {
	// contains filtered or unexported fields
}

Buffer 为可变长度切片缓冲,语义对齐标准库 bytes.Buffer,元素类型为 Data,底层切片类型为 Datas(须 ~[]Data)。 零值为空缓冲,可直接使用。

func NewBuffer added in v1.1.1

func NewBuffer[Datas ~[]Data, Data any]() *Buffer[Datas, Data]

NewBuffer 创建空缓冲。

func NewBufferFrom added in v1.1.1

func NewBufferFrom[Datas ~[]Data, Data any](buf Datas) *Buffer[Datas, Data]

NewBufferFrom 使用已有切片作为初始内容(取得 buf 所有权,调用后勿再使用传入的 buf)。

func (*Buffer[Datas, Data]) Available added in v1.1.1

func (b *Buffer[Datas, Data]) Available() int

Available 返回 buf 尾部尚未使用的容量(cap-len)。

func (*Buffer[Datas, Data]) AvailableBuffer added in v1.1.1

func (b *Buffer[Datas, Data]) AvailableBuffer() Datas

AvailableBuffer 返回 len 为 0、指向 buf 空闲尾部的切片,供追加后立即 Write 使用(与 bytes.Buffer.AvailableBuffer 一致)。

func (*Buffer[Datas, Data]) Cap added in v1.1.1

func (b *Buffer[Datas, Data]) Cap() int

Cap 返回底层切片总容量。

func (*Buffer[Datas, Data]) Datas added in v1.1.1

func (b *Buffer[Datas, Data]) Datas() Datas

Datas 返回长度等于 Len() 的切片,指向当前未读数据;下一次读写/Reset/Truncate 前有效。

func (*Buffer[Datas, Data]) Grow added in v1.1.1

func (b *Buffer[Datas, Data]) Grow(n int)

Grow 将容量至少再扩大 n;n 为负时 panic。

func (*Buffer[Datas, Data]) Len added in v1.1.1

func (b *Buffer[Datas, Data]) Len() int

Len 返回未读元素个数。

func (*Buffer[Datas, Data]) Next added in v1.1.1

func (b *Buffer[Datas, Data]) Next(n int) Datas

Next 返回接下来至多 n 个未读元素组成的切片,并推进读指针(与 bytes.Buffer.Next 一致)。

func (*Buffer[Datas, Data]) Read added in v1.1.1

func (b *Buffer[Datas, Data]) Read(p []Data) (n int, err error)

Read 从缓冲读出数据到 p;无数据可读且 len(p)>0 时返回 io.EOF。

func (*Buffer[Datas, Data]) ReadFrom added in v1.1.1

func (b *Buffer[Datas, Data]) ReadFrom(r Reader[Datas, Data]) (n int64, err error)

ReadFrom 从 r 读到 EOF 并追加到缓冲;返回值 n 为读到的元素个数(与 io.ReaderFrom 一致用 int64)。

func (*Buffer[Datas, Data]) ReadnFrom added in v1.1.1

func (b *Buffer[Datas, Data]) ReadnFrom(r Reader[Datas, Data], n int) (read int, err error)

ReadnFrom 从 r 最多读取 n 个元素并追加到缓冲;用于 Peek 等场景。

func (*Buffer[Datas, Data]) Reset added in v1.1.1

func (b *Buffer[Datas, Data]) Reset()

Reset 清空缓冲,保留底层数组供后续写入复用。

func (*Buffer[Datas, Data]) Truncate added in v1.1.1

func (b *Buffer[Datas, Data]) Truncate(n int)

Truncate 保留未读的前 n 个元素,仍复用已分配空间;n 非法时 panic。

func (*Buffer[Datas, Data]) Write added in v1.1.1

func (b *Buffer[Datas, Data]) Write(datas Datas) (n int, err error)

Write 追加 datas,必要时扩容;过大时 panic(ErrTooLarge)。

type CachedDataFetcher added in v1.0.29

type CachedDataFetcher[Data any] struct {
	*zap.Logger
	// contains filtered or unexported fields
}

func NewCachedDataFetcher added in v1.0.29

func NewCachedDataFetcher[Data any](fetcher CachedDataFetcherFetchFunc[Data]) *CachedDataFetcher[Data]

func NewCachedDataFetcherFromAnother added in v1.0.67

func NewCachedDataFetcherFromAnother[Data any, BasedData any](basedFetcher *CachedDataFetcher[BasedData], newDataFromBased func(BasedData) Data) *CachedDataFetcher[Data]

func NewCachedDataFetcherLite added in v1.0.29

func NewCachedDataFetcherLite[Data any](fetcher CachedDataFetcherFetchFuncLite[Data]) *CachedDataFetcher[Data]

func (*CachedDataFetcher[Data]) BuildAccessor added in v1.0.64

func (fetcher *CachedDataFetcher[Data]) BuildAccessor() *CachedDataFetcherAccessor[Data]

func (*CachedDataFetcher[Data]) Dup added in v1.0.31

func (fetcher *CachedDataFetcher[Data]) Dup() *CachedDataFetcher[Data]

func (*CachedDataFetcher[Data]) EnsureExpiresDuration added in v1.0.34

func (fetcher *CachedDataFetcher[Data]) EnsureExpiresDuration(expiresDuration time.Duration) *CachedDataFetcher[Data]

func (*CachedDataFetcher[Data]) Fetch added in v1.0.29

func (fetcher *CachedDataFetcher[Data]) Fetch(ctx context.Context) (Data, time.Time, error)

func (*CachedDataFetcher[Data]) FetchLite added in v1.0.37

func (fetcher *CachedDataFetcher[Data]) FetchLite(ctx context.Context) (data Data, err error)

func (*CachedDataFetcher[Data]) FetchWithExpires added in v1.0.34

func (fetcher *CachedDataFetcher[Data]) FetchWithExpires(ctx context.Context, expiresDuration time.Duration) (data Data, t time.Time, err error)

func (*CachedDataFetcher[Data]) FetchWithExpiresPro added in v1.0.64

func (fetcher *CachedDataFetcher[Data]) FetchWithExpiresPro(ctx context.Context, expiresDuration, fallbackDuration time.Duration, logger *zap.Logger) (data Data, ok bool)

func (*CachedDataFetcher[Data]) FetchWithSince added in v1.0.34

func (fetcher *CachedDataFetcher[Data]) FetchWithSince(ctx context.Context, since time.Time) (data Data, t time.Time, err error)

func (*CachedDataFetcher[Data]) Get added in v1.0.29

func (fetcher *CachedDataFetcher[Data]) Get() (Data, time.Time, bool)

func (*CachedDataFetcher[Data]) GetCached added in v1.0.34

func (fetcher *CachedDataFetcher[Data]) GetCached() (Data, time.Time)

func (*CachedDataFetcher[Data]) GetFetch added in v1.0.44

func (fetcher *CachedDataFetcher[Data]) GetFetch() func(ctx context.Context) (Data, time.Time, error)

func (*CachedDataFetcher[Data]) GetFetchLite added in v1.0.44

func (fetcher *CachedDataFetcher[Data]) GetFetchLite() func(ctx context.Context) (Data, error)

func (*CachedDataFetcher[Data]) GetRefresh added in v1.0.44

func (fetcher *CachedDataFetcher[Data]) GetRefresh() func(ctx context.Context) (Data, time.Time, error)

func (*CachedDataFetcher[Data]) GetWithExpires added in v1.0.34

func (fetcher *CachedDataFetcher[Data]) GetWithExpires(expiresDuration time.Duration) (Data, time.Time, bool)

func (*CachedDataFetcher[Data]) GetWithExpiresWarn added in v1.0.61

func (fetcher *CachedDataFetcher[Data]) GetWithExpiresWarn(expiresDuration time.Duration) (Data, bool)

func (*CachedDataFetcher[Data]) GetWithSince added in v1.0.34

func (fetcher *CachedDataFetcher[Data]) GetWithSince(since time.Time) (Data, time.Time, bool)

func (*CachedDataFetcher[Data]) GetWithSinceWarn added in v1.0.61

func (fetcher *CachedDataFetcher[Data]) GetWithSinceWarn(since time.Time) (data Data, ok bool)

func (*CachedDataFetcher[Data]) NewCallback added in v1.0.36

func (fetcher *CachedDataFetcher[Data]) NewCallback(callback CachedDataFetcherCallbackFunc[Data], timeout time.Duration) *CachedDataFetcherCallback[Data]

func (*CachedDataFetcher[Data]) NewCallbackLite added in v1.0.36

func (fetcher *CachedDataFetcher[Data]) NewCallbackLite(callback func(context.Context), timeout time.Duration) *CachedDataFetcherCallback[Data]

func (*CachedDataFetcher[Data]) PurgeCachedData added in v1.0.44

func (fetcher *CachedDataFetcher[Data]) PurgeCachedData()

func (*CachedDataFetcher[Data]) Refresh added in v1.0.29

func (fetcher *CachedDataFetcher[Data]) Refresh(ctx context.Context) (data Data, t time.Time, err error)

func (*CachedDataFetcher[Data]) RefreshLowerCache added in v1.0.69

func (fetcher *CachedDataFetcher[Data]) RefreshLowerCache(ctx context.Context) (data Data, t time.Time, err error)

func (*CachedDataFetcher[Data]) RefreshWithSinceTime added in v1.0.69

func (fetcher *CachedDataFetcher[Data]) RefreshWithSinceTime(ctx context.Context, since time.Time) (data Data, t time.Time, err error)

func (*CachedDataFetcher[Data]) RegisterCallback added in v1.0.36

func (fetcher *CachedDataFetcher[Data]) RegisterCallback(callback *CachedDataFetcherCallback[Data]) *CachedDataFetcherCallback[Data]

func (*CachedDataFetcher[Data]) RegisterCallbackFunc added in v1.0.69

func (fetcher *CachedDataFetcher[Data]) RegisterCallbackFunc(callback CachedDataFetcherCallbackFunc[Data], timeout time.Duration)

func (*CachedDataFetcher[Data]) RegisterCallbackFuncLite added in v1.0.37

func (fetcher *CachedDataFetcher[Data]) RegisterCallbackFuncLite(callback func(context.Context), timeout time.Duration)

func (*CachedDataFetcher[Data]) SinceTimeFromExpiresDuration added in v1.0.39

func (fetcher *CachedDataFetcher[Data]) SinceTimeFromExpiresDuration(expiresDuration time.Duration) (since time.Time)

func (*CachedDataFetcher[Data]) TriggerRefreshLowerCache added in v1.0.69

func (fetcher *CachedDataFetcher[Data]) TriggerRefreshLowerCache(ctx context.Context)

func (*CachedDataFetcher[Data]) WithCachedDataPurged added in v1.0.44

func (fetcher *CachedDataFetcher[Data]) WithCachedDataPurged() *CachedDataFetcher[Data]

func (*CachedDataFetcher[Data]) WithExpiresDuration added in v1.0.30

func (fetcher *CachedDataFetcher[Data]) WithExpiresDuration(duration time.Duration) *CachedDataFetcher[Data]

func (*CachedDataFetcher[Data]) WithFetcher added in v1.0.30

func (fetcher *CachedDataFetcher[Data]) WithFetcher(fetcherFunc CachedDataFetcherFetchFunc[Data]) *CachedDataFetcher[Data]

func (*CachedDataFetcher[Data]) WithLogger added in v1.0.57

func (fetcher *CachedDataFetcher[Data]) WithLogger(logger *zap.Logger) *CachedDataFetcher[Data]

func (*CachedDataFetcher[Data]) WithOthersSubscribed added in v1.0.38

func (fetcher *CachedDataFetcher[Data]) WithOthersSubscribed(timeout time.Duration, others ...interface {
	RegisterCallbackFuncLite(func(context.Context), time.Duration)
}) *CachedDataFetcher[Data]

type CachedDataFetcherAccessor added in v1.0.64

type CachedDataFetcherAccessor[Data any] struct {
	// contains filtered or unexported fields
}

func (*CachedDataFetcherAccessor[Data]) Dup added in v1.0.64

func (getter *CachedDataFetcherAccessor[Data]) Dup() *CachedDataFetcherAccessor[Data]

func (*CachedDataFetcherAccessor[Data]) Get added in v1.0.64

func (getter *CachedDataFetcherAccessor[Data]) Get() (data Data, ok bool)

func (*CachedDataFetcherAccessor[Data]) GetLogger added in v1.0.64

func (getter *CachedDataFetcherAccessor[Data]) GetLogger() *zap.Logger

func (*CachedDataFetcherAccessor[Data]) WithExpiresDuration added in v1.0.64

func (getter *CachedDataFetcherAccessor[Data]) WithExpiresDuration(expiresDuration time.Duration) *CachedDataFetcherAccessor[Data]

func (*CachedDataFetcherAccessor[Data]) WithFallbackDuration added in v1.0.64

func (getter *CachedDataFetcherAccessor[Data]) WithFallbackDuration(fallbackDuration time.Duration) *CachedDataFetcherAccessor[Data]

func (*CachedDataFetcherAccessor[Data]) WithLogExpired added in v1.0.64

func (getter *CachedDataFetcherAccessor[Data]) WithLogExpired(logExpired bool) *CachedDataFetcherAccessor[Data]

func (*CachedDataFetcherAccessor[Data]) WithLogger added in v1.0.64

func (getter *CachedDataFetcherAccessor[Data]) WithLogger(logger *zap.Logger) *CachedDataFetcherAccessor[Data]

type CachedDataFetcherCallback added in v1.0.36

type CachedDataFetcherCallback[Data any] struct {
	// contains filtered or unexported fields
}

func NewCachedDataFetcherCallback added in v1.0.36

func NewCachedDataFetcherCallback[Data any](callback func(context.Context, Data, time.Time), timeout time.Duration) *CachedDataFetcherCallback[Data]

func (*CachedDataFetcherCallback[Data]) Call added in v1.0.36

func (callback *CachedDataFetcherCallback[Data]) Call(data Data, lastFetchTime time.Time)

type CachedDataFetcherCallbackFunc added in v1.0.36

type CachedDataFetcherCallbackFunc[Data any] func(context.Context, Data, time.Time)

type CachedDataFetcherCallbacks added in v1.0.36

type CachedDataFetcherCallbacks[Data any] []*CachedDataFetcherCallback[Data]

func (CachedDataFetcherCallbacks[Data]) Append added in v1.0.36

func (callbacks CachedDataFetcherCallbacks[Data]) Append(others ...*CachedDataFetcherCallback[Data]) CachedDataFetcherCallbacks[Data]

func (CachedDataFetcherCallbacks[Data]) Call added in v1.0.36

func (callbacks CachedDataFetcherCallbacks[Data]) Call(data Data, lastFetchTime time.Time)

type CachedDataFetcherFetchFunc added in v1.0.38

type CachedDataFetcherFetchFunc[Data any] func(ctx context.Context, sinceTime time.Time) (Data, time.Time, error)

type CachedDataFetcherFetchFuncLite added in v1.0.38

type CachedDataFetcherFetchFuncLite[Data any] func(ctx context.Context) (Data, error)

type ChanPipe added in v1.1.1

type ChanPipe[Data any] struct {
	// contains filtered or unexported fields
}

func NewBufferedChanPipe added in v1.1.1

func NewBufferedChanPipe[Data any](cap int) *ChanPipe[Data]

func NewChanPipe added in v1.1.1

func NewChanPipe[Data any]() *ChanPipe[Data]

func (*ChanPipe[Data]) Cancel added in v1.1.1

func (pipe *ChanPipe[Data]) Cancel()

func (*ChanPipe[Data]) Canceled added in v1.1.1

func (pipe *ChanPipe[Data]) Canceled() <-chan struct{}

func (*ChanPipe[Data]) Close added in v1.1.1

func (pipe *ChanPipe[Data]) Close()

func (*ChanPipe[Data]) IsCanceled added in v1.1.1

func (pipe *ChanPipe[Data]) IsCanceled() bool

func (*ChanPipe[Data]) Reader added in v1.1.1

func (pipe *ChanPipe[Data]) Reader() <-chan Data

func (*ChanPipe[Data]) Writer added in v1.1.1

func (pipe *ChanPipe[Data]) Writer() chan<- Data

type CloseFunc added in v1.1.18

type CloseFunc func() error

func (CloseFunc) Close added in v1.1.18

func (close CloseFunc) Close() error

type Closers added in v1.1.22

type Closers []io.Closer

func NewClosers added in v1.1.22

func NewClosers(closers ...io.Closer) Closers

func (Closers) Append added in v1.1.22

func (closers Closers) Append(others ...io.Closer) Closers

func (Closers) Close added in v1.1.22

func (closers Closers) Close() error

func (Closers) Concat added in v1.1.22

func (closers Closers) Concat(others ...Closers) Closers

func (Closers) PurgeNil added in v1.1.22

func (closers Closers) PurgeNil() Closers

func (Closers) Simplify added in v1.1.22

func (closers Closers) Simplify() io.Closer

type ComparableSlice added in v1.0.8

type ComparableSlice[Data comparable] []Data

func NewComparableSlice added in v1.0.8

func NewComparableSlice[Data comparable](datas ...Data) ComparableSlice[Data]

func (ComparableSlice[Data]) AllMatch added in v1.0.8

func (slice ComparableSlice[Data]) AllMatch(f func(Data) bool) bool

func (ComparableSlice[Data]) AnyMatch added in v1.0.8

func (slice ComparableSlice[Data]) AnyMatch(f func(Data) bool) bool

func (ComparableSlice[Data]) Contain added in v1.0.11

func (slice ComparableSlice[Data]) Contain(data Data) bool

func (ComparableSlice[Data]) ContainAll added in v1.0.11

func (slice ComparableSlice[Data]) ContainAll(datas ...Data) bool

func (ComparableSlice[Data]) ContainAny added in v1.0.11

func (slice ComparableSlice[Data]) ContainAny(datas ...Data) bool

func (ComparableSlice[Data]) Dup added in v1.0.8

func (slice ComparableSlice[Data]) Dup() ComparableSlice[Data]

func (ComparableSlice[Data]) Filter added in v1.0.8

func (slice ComparableSlice[Data]) Filter(f func(Data) bool) ComparableSlice[Data]

func (ComparableSlice[Data]) ForEachPro added in v1.0.8

func (slice ComparableSlice[Data]) ForEachPro(f func(int, Data, ComparableSlice[Data]))

func (ComparableSlice[Data]) Map added in v1.0.8

func (slice ComparableSlice[Data]) Map(f func(Data) Data) Slice[Data]

func (ComparableSlice[Data]) Native added in v1.0.8

func (slice ComparableSlice[Data]) Native() []Data

func (ComparableSlice[Data]) NotNilSlice added in v1.0.8

func (slice ComparableSlice[Data]) NotNilSlice() ComparableSlice[Data]

type ContextValues added in v1.0.56

type ContextValues[Key comparable, Value any] map[Key]Value

func NewContextValues added in v1.0.56

func NewContextValues[Key comparable, Value any]() ContextValues[Key, Value]

func (ContextValues[Key, Value]) ApplyTo added in v1.0.56

func (values ContextValues[Key, Value]) ApplyTo(ctx context.Context) context.Context

func (ContextValues[Key, Value]) Empty added in v1.0.56

func (values ContextValues[Key, Value]) Empty() bool

func (ContextValues[Key, Value]) Len added in v1.0.56

func (values ContextValues[Key, Value]) Len() int

func (ContextValues[Key, Value]) With added in v1.0.56

func (values ContextValues[Key, Value]) With(key Key, value Value) ContextValues[Key, Value]

type ConvertWriter added in v1.1.18

type ConvertWriter[Inputs ~[]Input, Outputs ~[]Output, Input any, Output any] struct {
	NilNopCloseFunc
	// contains filtered or unexported fields
}

func NewConvertWriter added in v1.1.18

func NewConvertWriter[Inputs ~[]Input, Outputs ~[]Output, Input any, Output any](convert func(input Input) (Output, error), output Writer[Outputs, Output]) *ConvertWriter[Inputs, Outputs, Input, Output]

func (*ConvertWriter[Inputs, Outputs, Input, Output]) Write added in v1.1.18

func (converter *ConvertWriter[Inputs, Outputs, Input, Output]) Write(datas Inputs) (n int, err error)

type CountWriter added in v1.1.18

type CountWriter[Datas ~[]Data, Results ~[]Result, Data any, Result constraints.Integer] struct {
	// contains filtered or unexported fields
}

func (*CountWriter[Datas, Results, Data, Result]) Close added in v1.1.18

func (counter *CountWriter[Datas, Results, Data, Result]) Close() error

func (*CountWriter[Datas, Results, Data, Result]) GetCount added in v1.1.18

func (counter *CountWriter[Datas, Results, Data, Result]) GetCount() Result

func (*CountWriter[Datas, Results, Data, Result]) Write added in v1.1.18

func (counter *CountWriter[Datas, Results, Data, Result]) Write(datas Datas) (n int, err error)

type Counter added in v1.0.60

type Counter[Key comparable] map[Key]int

func Count added in v1.0.60

func Count[Datas ~[]Data, Data comparable](datas Datas) Counter[Data]

func CountByKey added in v1.0.53

func CountByKey[Datas ~[]Data, Data any, Key comparable](datas Datas, key func(Data) Key) Counter[Key]

func NewCounter added in v1.0.60

func NewCounter[Key comparable]() Counter[Key]

func (Counter[Key]) Decrease added in v1.0.60

func (counter Counter[Key]) Decrease(key Key) Counter[Key]

func (Counter[Key]) Increase added in v1.0.60

func (counter Counter[Key]) Increase(key Key) Counter[Key]

func (Counter[Key]) IncreaseValue added in v1.0.60

func (counter Counter[Key]) IncreaseValue(key Key, value int) Counter[Key]

func (Counter[Key]) NativeMap added in v1.0.60

func (counter Counter[Key]) NativeMap() map[Key]int

func (Counter[Key]) SumKeys added in v1.0.60

func (counter Counter[Key]) SumKeys(keys ...Key) (total int)

type Errors added in v1.0.26

type Errors []error

func MapWithError added in v1.0.26

func MapWithError[Datas ~[]Data, Result any, Data any](datas Datas, stopWhenError bool, mapper func(Data) (Result, error)) (results []Result, errs Errors)

func MapWithErrorPro added in v1.0.34

func MapWithErrorPro[Datas ~[]Data, Result any, Data any](datas Datas, stopWhenError bool, mapper func(int, Data, Datas) (Result, error)) (results []Result, errs Errors)

func NewErrors added in v1.0.54

func NewErrors(errs ...error) Errors

func (Errors) Append added in v1.0.54

func (errors Errors) Append(more ...error) Errors

func (Errors) Concat added in v1.0.54

func (errors Errors) Concat(mores ...Errors) Errors

func (Errors) Empty added in v1.0.26

func (errors Errors) Empty() bool

func (Errors) Error added in v1.0.26

func (errors Errors) Error() string

func (Errors) FirstError added in v1.0.26

func (errors Errors) FirstError() error

func (Errors) FirstOneOrZero added in v1.0.26

func (errors Errors) FirstOneOrZero() error

func (Errors) Len added in v1.0.26

func (errors Errors) Len() int

func (Errors) PurgeZero added in v1.0.26

func (errors Errors) PurgeZero() Errors

func (Errors) Simplify added in v1.0.46

func (errors Errors) Simplify() error

type IntOptionMeta added in v1.1.9

type IntOptionMeta[Data any] struct {
	Opt      func(int) Option[Data]
	Value    string
	Required bool
	Default  *int
}

func NewIntOptionMeta added in v1.1.9

func NewIntOptionMeta[Data any](opt func(int) Option[Data], value string) IntOptionMeta[Data]

func (IntOptionMeta[Data]) NewOption added in v1.1.9

func (meta IntOptionMeta[Data]) NewOption() (Option[Data], error)

type IntOptionMetas added in v1.1.9

type IntOptionMetas[Data any] []IntOptionMeta[Data]

func (IntOptionMetas[Data]) NewOptions added in v1.1.9

func (metas IntOptionMetas[Data]) NewOptions() (Options[Data], error)

type Iterator added in v1.0.35

type Iterator[Data any] interface {
	Len() int
	Data() Data
	Next() bool
}

type KeyValuePair added in v1.0.27

type KeyValuePair[Key any, Value any] struct {
	Key   Key
	Value Value
}

func NewKeyValuePair added in v1.1.11

func NewKeyValuePair[Key any, Value any](key Key, value Value) *KeyValuePair[Key, Value]

func (*KeyValuePair[Key, Value]) GetKey added in v1.0.56

func (pair *KeyValuePair[Key, Value]) GetKey() (key Key)

func (*KeyValuePair[Key, Value]) GetKeyValue added in v1.1.11

func (pair *KeyValuePair[Key, Value]) GetKeyValue() (key Key, value Value)

func (*KeyValuePair[Key, Value]) GetValue added in v1.1.8

func (pair *KeyValuePair[Key, Value]) GetValue() (value Value)

func (*KeyValuePair[Key, Value]) KeySeq added in v1.1.11

func (pair *KeyValuePair[Key, Value]) KeySeq() iter.Seq[Key]

func (*KeyValuePair[Key, Value]) KeyValueSeq added in v1.1.11

func (pair *KeyValuePair[Key, Value]) KeyValueSeq() iter.Seq2[Key, Value]

func (*KeyValuePair[Key, Value]) ValueSeq added in v1.1.11

func (pair *KeyValuePair[Key, Value]) ValueSeq() iter.Seq[Value]

type KeyValuePairPtrs added in v1.0.27

type KeyValuePairPtrs[Key any, Value any] []*KeyValuePair[Key, Value]

func MapKeyValuePairPtrs added in v1.0.27

func MapKeyValuePairPtrs[Map ~map[Key]Value, Key comparable, Value any](m Map) KeyValuePairPtrs[Key, Value]

func (KeyValuePairPtrs[Key, Value]) KeySeq added in v1.1.8

func (pairs KeyValuePairPtrs[Key, Value]) KeySeq() iter.Seq[Key]

func (KeyValuePairPtrs[Key, Value]) KeyValueSeq added in v1.1.8

func (pairs KeyValuePairPtrs[Key, Value]) KeyValueSeq() iter.Seq2[Key, Value]

func (KeyValuePairPtrs[Key, Value]) ToTypelessSlice added in v1.0.35

func (pairs KeyValuePairPtrs[Key, Value]) ToTypelessSlice() []any

func (KeyValuePairPtrs[Key, Value]) ValueSeq added in v1.1.8

func (pairs KeyValuePairPtrs[Key, Value]) ValueSeq() iter.Seq[Value]

type KeyValuePairs added in v1.0.27

type KeyValuePairs[Key any, Value any] []KeyValuePair[Key, Value]

func MapKeyValuePairs added in v1.0.27

func MapKeyValuePairs[Map ~map[Key]Value, Key comparable, Value any](m Map) KeyValuePairs[Key, Value]

func ZipToPairs added in v1.0.53

func ZipToPairs[Key any, Value any](keys []Key, values []Value) KeyValuePairs[Key, Value]

func (KeyValuePairs[Key, Value]) Append added in v1.0.56

func (pairs KeyValuePairs[Key, Value]) Append(others ...KeyValuePair[Key, Value]) KeyValuePairs[Key, Value]

func (KeyValuePairs[Key, Value]) KeySeq added in v1.1.8

func (pairs KeyValuePairs[Key, Value]) KeySeq() iter.Seq[Key]

func (KeyValuePairs[Key, Value]) KeyValueSeq added in v1.1.8

func (pairs KeyValuePairs[Key, Value]) KeyValueSeq() iter.Seq2[Key, Value]

func (KeyValuePairs[Key, Value]) Sort added in v1.0.87

func (pairs KeyValuePairs[Key, Value]) Sort(less func(a, b KeyValuePair[Key, Value]) bool) KeyValuePairs[Key, Value]

func (KeyValuePairs[Key, Value]) SortByKey added in v1.0.87

func (pairs KeyValuePairs[Key, Value]) SortByKey(less func(a, b Key) bool) KeyValuePairs[Key, Value]

func (KeyValuePairs[Key, Value]) SortByValue added in v1.0.87

func (pairs KeyValuePairs[Key, Value]) SortByValue(less func(a, b Value) bool) KeyValuePairs[Key, Value]

func (KeyValuePairs[Key, Value]) ToTypelessSlice added in v1.0.35

func (pairs KeyValuePairs[Key, Value]) ToTypelessSlice() []any

func (KeyValuePairs[Key, Value]) ValueSeq added in v1.1.8

func (pairs KeyValuePairs[Key, Value]) ValueSeq() iter.Seq[Value]

type LimitWriter added in v1.1.18

type LimitWriter[Datas ~[]Data, Data any] struct {
	// contains filtered or unexported fields
}

func NewLimitWriter added in v1.1.18

func NewLimitWriter[Datas ~[]Data, Data any](limit int, writer Writer[Datas, Data]) *LimitWriter[Datas, Data]

func (*LimitWriter[Datas, Data]) Write added in v1.1.18

func (writer *LimitWriter[Datas, Data]) Write(datas Datas) (int, error)

type MapWriter added in v1.1.18

type MapWriter[Inputs ~[]Input, Outputs ~[]Output, Input any, Output any] struct {
	NilNopCloseFunc
	// contains filtered or unexported fields
}

func NewMapWriter added in v1.1.18

func NewMapWriter[Inputs ~[]Input, Outputs ~[]Output, Input any, Output any](mapper func(input Input) Output, output Writer[Outputs, Output]) *MapWriter[Inputs, Outputs, Input, Output]

func (*MapWriter[Inputs, Outputs, Input, Output]) Write added in v1.1.18

func (mapper *MapWriter[Inputs, Outputs, Input, Output]) Write(datas Inputs) (n int, err error)

type Mapping added in v1.0.56

type Mapping[Key comparable, Value any] map[Key]Value

func NewMapping added in v1.0.56

func NewMapping[Key comparable, Value any]() Mapping[Key, Value]

func NewMappingWithCap added in v1.1.24

func NewMappingWithCap[Key comparable, Value any](cap int) Mapping[Key, Value]

func (Mapping[Key, Value]) Clear added in v1.1.24

func (m Mapping[Key, Value]) Clear()

func (Mapping[Key, Value]) Delete added in v1.1.24

func (m Mapping[Key, Value]) Delete(key Key)

func (Mapping[Key, Value]) Get added in v1.1.24

func (m Mapping[Key, Value]) Get(key Key) (_ Value)

func (Mapping[Key, Value]) KeyValuePairs added in v1.0.87

func (mapping Mapping[Key, Value]) KeyValuePairs() KeyValuePairs[Key, Value]

func (Mapping[Key, Value]) Keys added in v1.1.24

func (mapping Mapping[Key, Value]) Keys() []Key

func (Mapping[Key, Value]) Len added in v1.1.24

func (m Mapping[Key, Value]) Len() int

func (Mapping[Key, Value]) Load added in v1.1.24

func (m Mapping[Key, Value]) Load(key Key) (Value, bool)

func (Mapping[Key, Value]) LoadAndDelete added in v1.1.24

func (m Mapping[Key, Value]) LoadAndDelete(key Key) (value Value, ok bool)

func (Mapping[Key, Value]) LoadOrCreate added in v1.1.24

func (m Mapping[Key, Value]) LoadOrCreate(key Key, create func() Value) (Value, bool)

func (Mapping[Key, Value]) LoadOrStore added in v1.1.24

func (m Mapping[Key, Value]) LoadOrStore(key Key, value Value) (Value, bool)

func (Mapping[Key, Value]) Native added in v1.0.87

func (mapping Mapping[Key, Value]) Native() map[Key]Value

func (Mapping[Key, Value]) Store added in v1.1.24

func (m Mapping[Key, Value]) Store(key Key, value Value)

func (Mapping[Key, Value]) StoreOk added in v1.1.24

func (m Mapping[Key, Value]) StoreOk(key Key, value Value) (ok bool)

func (Mapping[Key, Value]) Swap added in v1.1.24

func (m Mapping[Key, Value]) Swap(key Key, value Value) (Value, bool)

func (Mapping[Key, Value]) SwapOk added in v1.1.24

func (m Mapping[Key, Value]) SwapOk(key Key, value Value) (previous Value, loaded bool, ok bool)

func (Mapping[Key, Value]) Values added in v1.1.24

func (m Mapping[Key, Value]) Values() []Value

type NilNopCloseFunc added in v1.1.18

type NilNopCloseFunc func() error

func (NilNopCloseFunc) Close added in v1.1.18

func (close NilNopCloseFunc) Close() error

type NilNopWriteFunc added in v1.1.18

type NilNopWriteFunc[Datas ~[]Data, Data any] func(datas Datas) (n int, err error)

func (NilNopWriteFunc[Datas, Data]) Write added in v1.1.18

func (write NilNopWriteFunc[Datas, Data]) Write(datas Datas) (n int, err error)

type NoOpIo added in v1.1.1

type NoOpIo[Datas ~[]Data, Data any] struct{}

NoOpIo 为空的 IO 操作,用于占位。

func (NoOpIo[Datas, Data]) Close added in v1.1.1

func (NoOpIo[Datas, Data]) Close() error

func (NoOpIo[Datas, Data]) Read added in v1.1.1

func (NoOpIo[Datas, Data]) Read(p []Data) (int, error)

func (NoOpIo[Datas, Data]) Write added in v1.1.1

func (NoOpIo[Datas, Data]) Write(p []Data) (int, error)

type NopCloser added in v1.1.18

type NopCloser struct{}

func (NopCloser) Close added in v1.1.18

func (nopCloser NopCloser) Close() error

type NopWriteCloser added in v1.1.18

type NopWriteCloser[Datas ~[]Data, Data any] struct {
	NopWriter[Datas, Data]
	NopCloser
}

func NewNopWriteCloser added in v1.1.18

func NewNopWriteCloser[Datas ~[]Data, Data any]() NopWriteCloser[Datas, Data]

type NopWriter added in v1.1.18

type NopWriter[Datas ~[]Data, Data any] struct{}

func NewNopWriter added in v1.1.18

func NewNopWriter[Datas ~[]Data, Data any]() NopWriter[Datas, Data]

func (NopWriter[Datas, Data]) Write added in v1.1.18

func (nopWriter NopWriter[Datas, Data]) Write(datas Datas) (n int, err error)

type Number added in v1.1.8

type Number interface {
	constraints.Integer | constraints.Float
}

type Numbers added in v1.1.8

type Numbers[Data Number] []Data

func (Numbers[Data]) Append added in v1.1.8

func (numbers Numbers[Data]) Append(others ...Data) Numbers[Data]

func (Numbers[Data]) AscPercentFor added in v1.1.8

func (numbers Numbers[Data]) AscPercentFor(target Data) float64

func (Numbers[Data]) AscPositionFor added in v1.1.8

func (numbers Numbers[Data]) AscPositionFor(target Data) int

func (Numbers[Data]) AscRatioFor added in v1.1.8

func (numbers Numbers[Data]) AscRatioFor(target Data) float64

func (Numbers[Data]) Avg added in v1.1.8

func (numbers Numbers[Data]) Avg() Data

func (Numbers[Data]) Concat added in v1.1.8

func (numbers Numbers[Data]) Concat(others ...Numbers[Data]) Numbers[Data]

func (Numbers[Data]) DescPercentFor added in v1.1.8

func (numbers Numbers[Data]) DescPercentFor(target Data) float64

func (Numbers[Data]) DescPositionFor added in v1.1.8

func (numbers Numbers[Data]) DescPositionFor(target Data) int

func (Numbers[Data]) DescRatioFor added in v1.1.8

func (numbers Numbers[Data]) DescRatioFor(target Data) float64

func (Numbers[Data]) Dup added in v1.1.8

func (numbers Numbers[Data]) Dup() Numbers[Data]

func (Numbers[Data]) Empty added in v1.1.8

func (numbers Numbers[Data]) Empty() bool

func (Numbers[Data]) Len added in v1.1.8

func (numbers Numbers[Data]) Len() int

func (Numbers[Data]) Max added in v1.1.8

func (numbers Numbers[Data]) Max() Data

func (Numbers[Data]) Min added in v1.1.8

func (numbers Numbers[Data]) Min() Data

func (Numbers[Data]) Negtives added in v1.1.8

func (numbers Numbers[Data]) Negtives() Numbers[Data]

func (Numbers[Data]) Positives added in v1.1.8

func (numbers Numbers[Data]) Positives() Numbers[Data]

func (Numbers[Data]) PurgeZero added in v1.1.8

func (numbers Numbers[Data]) PurgeZero() Numbers[Data]

func (Numbers[Data]) Sort added in v1.1.8

func (numbers Numbers[Data]) Sort() Numbers[Data]

func (Numbers[Data]) SortAsc added in v1.1.8

func (numbers Numbers[Data]) SortAsc() Numbers[Data]

func (Numbers[Data]) SortDesc added in v1.1.8

func (numbers Numbers[Data]) SortDesc() Numbers[Data]

func (Numbers[Data]) SortPro added in v1.1.8

func (numbers Numbers[Data]) SortPro(less func(a, b Data) bool) Numbers[Data]

func (Numbers[Data]) Sum added in v1.1.8

func (numbers Numbers[Data]) Sum() Data

type Option added in v1.1.1

type Option[Data any] func(Data)

func NewOption added in v1.1.1

func NewOption[Data any](opt func(Data)) Option[Data]

func (Option[Data]) Apply added in v1.1.1

func (opt Option[Data]) Apply(data Data) Data

func (Option[Data]) IsNil added in v1.1.9

func (opt Option[Data]) IsNil() bool

type Options added in v1.1.1

type Options[Data any] []Option[Data]

func NewOptions added in v1.1.1

func NewOptions[Data any](opts ...Option[Data]) Options[Data]

func (Options[Data]) Append added in v1.1.9

func (opts Options[Data]) Append(more ...Option[Data]) Options[Data]

func (Options[Data]) Apply added in v1.1.1

func (opts Options[Data]) Apply(data Data) Data

func (Options[Data]) ParseAndAppendIntOptions added in v1.1.9

func (opts Options[Data]) ParseAndAppendIntOptions(metas IntOptionMetas[Data]) (Options[Data], error)

func (Options[Data]) PurgeNil added in v1.1.9

func (opts Options[Data]) PurgeNil() Options[Data]

type PeekReader added in v1.1.1

type PeekReader[Datas ~[]Data, Data any] struct {
	// contains filtered or unexported fields
}

func NewPeekReader added in v1.1.1

func NewPeekReader[Datas ~[]Data, Data any](r Reader[Datas, Data]) *PeekReader[Datas, Data]

NewPeekReader 包装 r:未 Peek 时 Read 直接走 r;Peek 后 Read 先消费预读缓冲再读底层。

func (*PeekReader[Datas, Data]) Datas added in v1.1.1

func (r *PeekReader[Datas, Data]) Datas() Datas

Datas 返回当前预读缓冲中的未读数据;尚未 Peek 时为 nil。

func (*PeekReader[Datas, Data]) Len added in v1.1.1

func (r *PeekReader[Datas, Data]) Len() int

Len 返回预读缓冲未读长度;尚未 Peek 时为 0。

func (*PeekReader[Datas, Data]) Peek added in v1.1.1

func (r *PeekReader[Datas, Data]) Peek(n int) (int, error)

Peek 预读 n 个数据,读到新数据时,将原始 Reader 包装为 MultiReader(buffer, original),后续 Read 时先消费预读缓冲再读底层。

func (*PeekReader[Datas, Data]) Read added in v1.1.1

func (r *PeekReader[Datas, Data]) Read(p []Data) (n int, err error)

读取数据,如果预读缓冲为空,则使用原始 Reader 读取

type PipeParser added in v1.1.18

type PipeParser[
	SrcDatas ~[]SrcData,
	ResultDatas ~[]ResultData,
	SrcData any,
	ResultData any,
] struct {
	Writer[SrcDatas, SrcData]
	io.Closer
	// contains filtered or unexported fields
}

func NewPipeParser added in v1.1.18

func NewPipeParser[
	SrcDatas ~[]SrcData,
	ResultDatas ~[]ResultData,
	SrcData any,
	ResultData any,
](
	pipe func() (ReadCloser[SrcDatas, SrcData], WriteCloser[SrcDatas, SrcData]),
	output Writer[ResultDatas, ResultData],
	readParse func(reader Reader[SrcDatas, SrcData]) (ResultData, error),
) *PipeParser[SrcDatas, ResultDatas, SrcData, ResultData]

func (*PipeParser[SrcDatas, ResultDatas, SrcData, ResultData]) CloseAndJoin added in v1.1.18

func (parser *PipeParser[SrcDatas, ResultDatas, SrcData, ResultData]) CloseAndJoin()

func (*PipeParser[SrcDatas, ResultDatas, SrcData, ResultData]) Join added in v1.1.18

func (parser *PipeParser[SrcDatas, ResultDatas, SrcData, ResultData]) Join()

type ProcessWriter added in v1.1.18

type ProcessWriter[Datas ~[]Data, Data any] struct {
	// contains filtered or unexported fields
}

func NewPrinter added in v1.1.18

func NewPrinter[Datas ~[]Data, Data any](fout *os.File) *ProcessWriter[Datas, Data]

func NewProcessWriter added in v1.1.18

func NewProcessWriter[Datas ~[]Data, Data any](process func(data Data) (err error)) *ProcessWriter[Datas, Data]

func (*ProcessWriter[Datas, Data]) Write added in v1.1.18

func (processor *ProcessWriter[Datas, Data]) Write(datas Datas) (n int, err error)

type ReadCloser added in v1.1.18

type ReadCloser[Datas ~[]Data, Data any] interface {
	Reader[Datas, Data]
	io.Closer
}

func NewReadCloser added in v1.1.23

func NewReadCloser[Datas ~[]Data, Data any](reader Reader[Datas, Data], closer io.Closer) ReadCloser[Datas, Data]

type Reader added in v1.1.1

type Reader[Datas ~[]Data, Data any] interface {
	Read(p []Data) (n int, err error)
}

func MultiReader added in v1.1.1

func MultiReader[Datas ~[]Data, Data any](readers ...Reader[Datas, Data]) Reader[Datas, Data]

MultiReader 返回按顺序串联多个 Reader 的逻辑 Reader;全部读完后再 Read 返回 io.EOF。 任一子 Reader 返回非 nil 且非 io.EOF 的错误时,该错误会向上返回。

func ReaderFromSeq added in v1.1.6

func ReaderFromSeq[Datas ~[]Data, Data any](seq iter.Seq[Data]) Reader[Datas, Data]

type ReduceWriter added in v1.1.18

type ReduceWriter[Datas ~[]Data, Results ~[]Result, Data any, Result any] struct {
	// contains filtered or unexported fields
}

func NewReduceWriter added in v1.1.18

func NewReduceWriter[Datas ~[]Data, Results ~[]Result, Data any, Result any](reduce func(result Result, data Data) Result, output Writer[Results, Result]) *ReduceWriter[Datas, Results, Data, Result]

func (*ReduceWriter[Datas, Results, Data, Result]) Close added in v1.1.18

func (writer *ReduceWriter[Datas, Results, Data, Result]) Close(datas Datas) (err error)

func (ReduceWriter) Result added in v1.1.18

func (buffer ReduceWriter) Result() (result Result)

func (ReduceWriter) Write added in v1.1.18

func (buffer ReduceWriter) Write(datas Datas) (n int, err error)

type ResumeReader added in v1.1.6

type ResumeReader[Datas ~[]Data, Data any] struct {
	// contains filtered or unexported fields
}

ResumeReader 出错续读:底层 Read 返回非 nil 且非 io.EOF 时,若底层实现 closer 则先关闭, 再以当前已成功交付给调用方的元素个数为 offset 调用 factory 创建新 Reader,并继续本次 Read(填满 p)。 offset 语义:从逻辑流起点算起,此前各次 Read 已累计返回给调用方的 Data 元素个数。

func NewResumeReader added in v1.1.6

func NewResumeReader[Datas ~[]Data, Data any](factory func(offset int) (Reader[Datas, Data], error), triesPerRead int) *ResumeReader[Datas, Data]

NewResumeReader 使用 factory 延迟打开底层;factory(offset) 应返回从逻辑流第 offset 个元素起的 Reader。

func (*ResumeReader[Datas, Data]) Read added in v1.1.6

func (rr *ResumeReader[Datas, Data]) Read(p []Data) (total int, err error)

Read 实现 Reader;底层非 EOF 错误时会关闭并换 reader 后重试,直到成功、EOF 或 factory 失败。

type RingBuffer added in v1.0.95

type RingBuffer[Datas ~[]Data, Data any] struct {
	BoundedBuffer[Datas, Data]
	// contains filtered or unexported fields
}

CircularBuffer 循环缓冲区,实现 io.Writer 接口 保留最后 size 字节的数据,新数据会覆盖旧数据 采用动态扩容策略,按写入量逐步增长,避免一次性分配大内存

func NewRingBuffer added in v1.0.95

func NewRingBuffer[Datas ~[]Data, Data any](size int) *RingBuffer[Datas, Data]

NewRingBuffer 创建新的循环缓冲区 缓冲区采用动态扩容策略,初始为空,随写入量增长

func (*RingBuffer[Datas, Data]) Datas added in v1.0.95

func (rb *RingBuffer[Datas, Data]) Datas() Datas

Datas 获取缓冲区中的数据(最后写入的字节)

func (*RingBuffer[Datas, Data]) IsTruncated added in v1.0.95

func (rb *RingBuffer[Datas, Data]) IsTruncated() bool

IsTruncated 返回是否被截断(写入的数据超过缓冲区大小)

func (*RingBuffer[Datas, Data]) Reset added in v1.0.95

func (rb *RingBuffer[Datas, Data]) Reset()

Reset 重置缓冲区

func (*RingBuffer[Datas, Data]) TotalWritten added in v1.0.95

func (rb *RingBuffer[Datas, Data]) TotalWritten() int64

TotalWritten 返回总共写入的字节数

func (*RingBuffer[Datas, Data]) Write added in v1.0.95

func (rb *RingBuffer[Datas, Data]) Write(datas Datas) (n int, err error)

type Seq2s added in v1.1.6

type Seq2s[K any, V any] []iter.Seq2[K, V]

func NewSeq2s added in v1.1.6

func NewSeq2s[K any, V any](seqs ...iter.Seq2[K, V]) Seq2s[K, V]

func (Seq2s[K, V]) AsSeq2 added in v1.1.6

func (seqs Seq2s[K, V]) AsSeq2() iter.Seq2[K, V]

func (Seq2s[K, V]) Seq2 added in v1.1.6

func (seqs Seq2s[K, V]) Seq2(yield func(K, V) bool)

type SeqReader added in v1.1.6

type SeqReader[Datas ~[]Data, Data any] iter.Seq[Data]

func (SeqReader[Datas, Data]) Read added in v1.1.6

func (r SeqReader[Datas, Data]) Read(p []Data) (n int, err error)

type Seqs added in v1.1.6

type Seqs[Data any] []iter.Seq[Data]

func NewSeqs added in v1.1.6

func NewSeqs[Data any](seqs ...iter.Seq[Data]) Seqs[Data]

func (Seqs[Data]) AsSeq added in v1.1.6

func (seqs Seqs[Data]) AsSeq() iter.Seq[Data]

func (Seqs[Data]) Seq added in v1.1.6

func (seqs Seqs[Data]) Seq(yield func(Data) bool)

type Set

type Set[Data comparable] map[Data]struct{}

func NewEmptySet

func NewEmptySet[Data comparable]() Set[Data]

func NewSet

func NewSet[Data comparable](datas ...Data) Set[Data]

func (Set[Data]) Add

func (set Set[Data]) Add(data Data) Set[Data]

func (Set[Data]) AddX added in v1.0.11

func (set Set[Data]) AddX(datas ...Data) Set[Data]

func (Set[Data]) Contain

func (set Set[Data]) Contain(data Data) bool

func (Set[Data]) ContainAll added in v1.0.49

func (set Set[Data]) ContainAll(datas ...Data) bool

func (Set[Data]) ContainAny added in v1.0.49

func (set Set[Data]) ContainAny(datas ...Data) bool

func (Set[Data]) Difference

func (set Set[Data]) Difference(other Set[Data]) Set[Data]

func (Set[Data]) Dup

func (set Set[Data]) Dup() Set[Data]

func (Set[Data]) Empty

func (set Set[Data]) Empty() bool

func (Set[Data]) Equal

func (set Set[Data]) Equal(other Set[Data]) bool

func (Set[Data]) FirstAppear added in v1.0.8

func (set Set[Data]) FirstAppear(datas ...Data) (result Data)

func (Set[Data]) Intersection

func (set Set[Data]) Intersection(other Set[Data]) Set[Data]

func (Set[Data]) Len

func (set Set[Data]) Len() int

func (Set[Data]) Merge added in v1.0.11

func (set Set[Data]) Merge(other Set[Data]) Set[Data]

func (Set[Data]) Pop

func (set Set[Data]) Pop(data Data) Set[Data]

func (Set[Data]) Purge added in v1.0.11

func (set Set[Data]) Purge(other Set[Data]) Set[Data]

func (Set[Data]) Push

func (set Set[Data]) Push(data Data) Set[Data]

func (Set[Data]) PushX

func (set Set[Data]) PushX(datas ...Data) Set[Data]

func (Set[Data]) Slice

func (set Set[Data]) Slice() Slice[Data]

func (Set[Data]) SymmetricDifference

func (set Set[Data]) SymmetricDifference(other Set[Data]) Set[Data]

func (Set[Data]) Union

func (set Set[Data]) Union(other Set[Data]) Set[Data]

type SkipWriter added in v1.1.18

type SkipWriter[Datas ~[]Data, Data any] struct {
	// contains filtered or unexported fields
}

func NewSkipWriter added in v1.1.18

func NewSkipWriter[Datas ~[]Data, Data any](skip int, writer Writer[Datas, Data]) *SkipWriter[Datas, Data]

func (*SkipWriter[Datas, Data]) Write added in v1.1.18

func (writer *SkipWriter[Datas, Data]) Write(datas Datas) (int, error)

type Slice added in v1.0.8

type Slice[Data any] []Data

func NewSlice added in v1.0.6

func NewSlice[Data any](datas ...Data) Slice[Data]

func NewSliceFromSeq added in v1.1.8

func NewSliceFromSeq[Data any](seq iter.Seq[Data]) Slice[Data]

func (Slice[Data]) AllMatch added in v1.0.8

func (slice Slice[Data]) AllMatch(f func(Data) bool) bool

func (Slice[Data]) AnyMatch added in v1.0.8

func (slice Slice[Data]) AnyMatch(f func(Data) bool) bool

func (Slice[Data]) Append added in v1.0.57

func (slice Slice[Data]) Append(datas ...Data) Slice[Data]

func (Slice[Data]) Concat added in v1.0.57

func (slice Slice[Data]) Concat(others ...Slice[Data]) Slice[Data]

func (Slice[Data]) DataSeq added in v1.1.6

func (slice Slice[Data]) DataSeq() iter.Seq[Data]

func (Slice[Data]) Dup added in v1.0.8

func (slice Slice[Data]) Dup() Slice[Data]

func (Slice[Data]) Empty added in v1.1.8

func (slice Slice[Data]) Empty() bool

func (Slice[Data]) Filter added in v1.0.8

func (slice Slice[Data]) Filter(f func(Data) bool) Slice[Data]

func (Slice[Data]) FilterPro added in v1.0.14

func (slice Slice[Data]) FilterPro(f func(int, Data, Slice[Data]) bool) Slice[Data]

func (Slice[Data]) ForEach added in v1.0.14

func (slice Slice[Data]) ForEach(f func(Data))

func (Slice[Data]) ForEachPro added in v1.0.8

func (slice Slice[Data]) ForEachPro(f func(int, Data, Slice[Data]))

func (Slice[Data]) IndexDataSeq added in v1.1.6

func (slice Slice[Data]) IndexDataSeq() iter.Seq2[int, Data]

func (Slice[Data]) IndexSeq added in v1.1.6

func (slice Slice[Data]) IndexSeq() iter.Seq[int]

func (Slice[Data]) Len added in v1.1.8

func (slice Slice[Data]) Len() int

func (Slice[Data]) Map added in v1.0.8

func (slice Slice[Data]) Map(f func(Data) Data) Slice[Data]

func (Slice[Data]) MapPro added in v1.0.14

func (slice Slice[Data]) MapPro(f func(int, Data, Slice[Data]) Data) Slice[Data]

func (Slice[Data]) Native added in v1.0.8

func (slice Slice[Data]) Native() []Data

func (Slice[Data]) NotNilSlice added in v1.0.8

func (slice Slice[Data]) NotNilSlice() Slice[Data]

type SyncMap added in v1.1.9

type SyncMap[Key comparable, Value any] struct {
	// contains filtered or unexported fields
}

func NewSyncMap added in v1.1.9

func NewSyncMap[Key comparable, Value any]() *SyncMap[Key, Value]

func NewSyncMapPro added in v1.1.24

func NewSyncMapPro[Key comparable, Value any](cap int, createFunc func(context.Context, Key) (Value, error)) *SyncMap[Key, Value]

func (*SyncMap[Key, Value]) Clear added in v1.1.24

func (m *SyncMap[Key, Value]) Clear()

func (*SyncMap[Key, Value]) Delete added in v1.1.9

func (m *SyncMap[Key, Value]) Delete(key Key)

func (*SyncMap[Key, Value]) Empty added in v1.1.9

func (m *SyncMap[Key, Value]) Empty() bool

func (*SyncMap[Key, Value]) Get added in v1.1.24

func (m *SyncMap[Key, Value]) Get(key Key) Value

func (*SyncMap[Key, Value]) Keys added in v1.1.9

func (m *SyncMap[Key, Value]) Keys() []Key

func (*SyncMap[Key, Value]) Len added in v1.1.9

func (m *SyncMap[Key, Value]) Len() int

func (*SyncMap[Key, Value]) Load added in v1.1.9

func (m *SyncMap[Key, Value]) Load(key Key) (value Value, loaded bool)

func (*SyncMap[Key, Value]) LoadAndDelete added in v1.1.9

func (m *SyncMap[Key, Value]) LoadAndDelete(key Key) (value Value, loaded bool)

func (*SyncMap[Key, Value]) LoadOrCreate added in v1.1.9

func (m *SyncMap[Key, Value]) LoadOrCreate(ctx context.Context, key Key, create func(ctx context.Context, key Key) (Value, error)) (value Value, loaded bool, err error)

func (*SyncMap[Key, Value]) LoadOrCreateLite added in v1.1.9

func (m *SyncMap[Key, Value]) LoadOrCreateLite(ctx context.Context, key Key, create func() Value) (Value, bool)

func (*SyncMap[Key, Value]) LoadOrStore added in v1.1.9

func (m *SyncMap[Key, Value]) LoadOrStore(key Key, newValue Value) (value Value, loaded bool)

func (*SyncMap[Key, Value]) Native added in v1.1.9

func (m *SyncMap[Key, Value]) Native() map[Key]Value

func (*SyncMap[Key, Value]) Store added in v1.1.9

func (m *SyncMap[Key, Value]) Store(key Key, value Value)

func (*SyncMap[Key, Value]) StoreOk added in v1.1.24

func (m *SyncMap[Key, Value]) StoreOk(key Key, value Value) (ok bool)

func (*SyncMap[Key, Value]) Swap added in v1.1.9

func (m *SyncMap[Key, Value]) Swap(key Key, value Value) (Value, bool)

func (*SyncMap[Key, Value]) SwapMapping added in v1.1.24

func (m *SyncMap[Key, Value]) SwapMapping(new Mapping[Key, Value]) Mapping[Key, Value]

func (*SyncMap[Key, Value]) SwapOk added in v1.1.24

func (m *SyncMap[Key, Value]) SwapOk(key Key, value Value) (old Value, hasOld bool, ok bool)

func (*SyncMap[Key, Value]) Values added in v1.1.9

func (m *SyncMap[Key, Value]) Values() []Value

type TimedValue added in v1.0.37

type TimedValue[Value any] struct {
	// contains filtered or unexported fields
}

func NewTimedValue added in v1.0.37

func NewTimedValue[Value any](value Value, t time.Time) *TimedValue[Value]

func (*TimedValue[Value]) Time added in v1.0.37

func (timed *TimedValue[Value]) Time() (t time.Time)

func (*TimedValue[Value]) Value added in v1.0.37

func (timed *TimedValue[Value]) Value() (value Value)

func (*TimedValue[Value]) ValueAndTime added in v1.0.37

func (timed *TimedValue[Value]) ValueAndTime() (value Value, t time.Time)

type TruncatedBuffer added in v1.0.95

type TruncatedBuffer[Datas ~[]Data, Data any] struct {
	BoundedBuffer[Datas, Data]
	// contains filtered or unexported fields
}

func NewTruncatedBuffer added in v1.0.95

func NewTruncatedBuffer[Datas ~[]Data, Data any](size int) *TruncatedBuffer[Datas, Data]

func (*TruncatedBuffer[Datas, Data]) IsTruncated added in v1.0.95

func (tb *TruncatedBuffer[Datas, Data]) IsTruncated() bool

func (*TruncatedBuffer[Datas, Data]) Reset added in v1.0.95

func (tb *TruncatedBuffer[Datas, Data]) Reset()

func (*TruncatedBuffer[Datas, Data]) TotalWritten added in v1.0.95

func (tb *TruncatedBuffer[Datas, Data]) TotalWritten() int64

func (*TruncatedBuffer[Datas, Data]) Write added in v1.0.95

func (tb *TruncatedBuffer[Datas, Data]) Write(datas Datas) (int, error)

type UnaryWriteFunc added in v1.1.18

type UnaryWriteFunc[Datas ~[]Data, Data any] func(data Data) (err error)

func NewUnaryWriteFunc added in v1.1.18

func NewUnaryWriteFunc[Datas ~[]Data, Data any](write func(data Data) (err error)) UnaryWriteFunc[Datas, Data]

func (UnaryWriteFunc[Datas, Data]) Write added in v1.1.18

func (write UnaryWriteFunc[Datas, Data]) Write(datas Datas) (n int, err error)

type WriteBuffer added in v1.1.18

type WriteBuffer[Datas ~[]Data, Data any] struct {
	// contains filtered or unexported fields
}

func NewWriteBuffer added in v1.1.18

func NewWriteBuffer[Datas ~[]Data, Data any]() *WriteBuffer[Datas, Data]

func (*WriteBuffer[Datas, Data]) Datas added in v1.1.18

func (buffer *WriteBuffer[Datas, Data]) Datas() Datas

func (*WriteBuffer[Datas, Data]) Write added in v1.1.18

func (buffer *WriteBuffer[Datas, Data]) Write(datas Datas) (n int, err error)

type WriteCloser added in v1.1.6

type WriteCloser[Datas ~[]Data, Data any] interface {
	Writer[Datas, Data]
	io.Closer
}

func NewNopCloseWriter added in v1.1.18

func NewNopCloseWriter[Datas ~[]Data, Data any](writer Writer[Datas, Data]) WriteCloser[Datas, Data]

func NewWriteCloser added in v1.1.18

func NewWriteCloser[Datas ~[]Data, Data any](writer Writer[Datas, Data], closer io.Closer) WriteCloser[Datas, Data]

type WriteClosers added in v1.1.22

type WriteClosers[Datas ~[]Data, Data any] []WriteCloser[Datas, Data]

func NewWriteClosers added in v1.1.23

func NewWriteClosers[Datas ~[]Data, Data any](writeClosers ...WriteCloser[Datas, Data]) WriteClosers[Datas, Data]

func (WriteClosers[Datas, Data]) AsClosers added in v1.1.22

func (writeClosers WriteClosers[Datas, Data]) AsClosers() Closers

func (WriteClosers[Datas, Data]) AsWriters added in v1.1.22

func (writeClosers WriteClosers[Datas, Data]) AsWriters() Writers[Datas, Data]

type WriteFunc added in v1.1.18

type WriteFunc[Datas any, Data any] func(datas Datas) (n int, err error)

func (WriteFunc[Datas, Data]) Write added in v1.1.18

func (write WriteFunc[Datas, Data]) Write(datas Datas) (n int, err error)

type Writer added in v1.1.6

type Writer[Datas ~[]Data, Data any] interface {
	Write(datas Datas) (n int, err error)
}

type Writers added in v1.1.18

type Writers[Datas ~[]Data, Data any] []Writer[Datas, Data]

func MultiWriter added in v1.1.18

func MultiWriter[Datas ~[]Data, Data any](writers ...Writer[Datas, Data]) Writers[Datas, Data]

func NewWriters added in v1.1.18

func NewWriters[Datas ~[]Data, Data any](writers ...Writer[Datas, Data]) Writers[Datas, Data]

func (Writers[Datas, Data]) Append added in v1.1.18

func (writers Writers[Datas, Data]) Append(others ...Writer[Datas, Data]) Writers[Datas, Data]

func (Writers[Datas, Data]) Close added in v1.1.22

func (writers Writers[Datas, Data]) Close() error

func (Writers[Datas, Data]) Closers added in v1.1.22

func (writers Writers[Datas, Data]) Closers() Closers

func (Writers[Datas, Data]) MultiWriter added in v1.1.22

func (writers Writers[Datas, Data]) MultiWriter() Writer[Datas, Data]

func (Writers[Datas, Data]) Native added in v1.1.18

func (writers Writers[Datas, Data]) Native() []Writer[Datas, Data]

func (Writers[Datas, Data]) PurgeNil added in v1.1.18

func (writers Writers[Datas, Data]) PurgeNil() Writers[Datas, Data]

func (Writers[Datas, Data]) ValidClosers added in v1.1.22

func (writers Writers[Datas, Data]) ValidClosers() Closers

func (Writers[Datas, Data]) Write added in v1.1.18

func (writers Writers[Datas, Data]) Write(datas Datas) (n int, err error)

Jump to

Keyboard shortcuts

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