函数名 函数描述/介绍 x.All All returns true if all elements of the iterable are not empty (or if the iterable is empty) x.Any Any returns true if any element of the iterable is not empty. If the iterable is empty, return False. x.Chunk Chunk creates an array of elements split into groups with the length of size. If array can't be split evenly, the final chunk will be the remainin... x.Contains Contains returns true if an element is present in a iteratee. x.ConvertToMap x.Difference Difference returns the difference between two collections. x.Drop Drop creates an array/slice with n
elements dropped from the beginning. x.Equal IsEqual returns if the two objects are equal x.Every Every returns true if every element is present in a iteratee. x.Filter x.Find x.Foreach x.ForeachRight x.GC x.GCPercent SetGCPercent sets the garbage collection target percentage: a collection is triggered when the ratio of freshly allocated data to live data remaining ... x.Head Head gets the first element of array. x.If x.IndexOf IndexOf gets the index at which the first occurrence of value is found in array or return -1 if the value cannot be found x.Intersect x.IsSubset Subset returns true if collection x is a subset of y. x.Keys Keys creates an array of the own enumerable map keys or struct field names. x.Map x.Max x.Min x.Range x.Reduce x.RemoveRepeat Uniq creates an array with unique values. x.Retry retry 对第二个参数作为函数的情况,重试N次,如果第二个参数返回值是 true,则重试,否则就结束,如果遇到错误,停止重试 x.Reverse Reverse transforms an array the first element will become the last, the second element will become the second to last, etc. x.Shift x.Shuffle Shuffle creates an array of shuffled values x.Some Some returns true if atleast one element is present in an iteratee. x.Sort SliceStable sorts the slice x using the provided less function, keeping equal elements in their original order. It panics if x is not a slice. The le... x.Subtract Subtract returns the subtraction between two collections. x.Sum Sum computes the sum of the values in array. x.Tail Tail gets all but the first element of array. x.ToFloat64 ToFloat64 converts any numeric value to float64. x.ToMap ToMap transforms a slice of instances to a Map. []Foo => Map<int, Foo> x.Values Values creates an array of the own enumerable map values or struct field values. x.WaitConnect WaitConnect 等待一个地址的端口开放或指导超时时间,如果超时则返回错误,这通常用于等待并确保一个服务启动 x.Zip Zip returns a list of tuples, where the i-th tuple contains the i-th element from each of the input iterables. The returned list is truncated in lengt...
函数定义# All# 详细描述# All returns true if all elements of the iterable are not empty (or if the iterable is empty)
All(objs ...any) bool
返回值# Any# 详细描述# Any returns true if any element of the iterable is not empty. If the iterable is empty, return False.
Any(objs ...any) bool
返回值# Chunk# 详细描述# Chunk creates an array of elements split into groups with the length of size.
If array can't be split evenly, the final chunk will be
the remaining element.
Chunk(arr any, size int) any
返回值# Contains# 详细描述# Contains returns true if an element is present in a iteratee.
Contains(in any, elem any) bool
返回值# ConvertToMap# 详细描述# ConvertToMap(i any) map[string][]string
返回值# 返回值(顺序) 返回值类型 返回值解释 r1 map[string][]string
Difference# 详细描述# Difference returns the difference between two collections.
Difference(x any, y any) (any, any)
返回值# 返回值(顺序) 返回值类型 返回值解释 r1 any
r2 any
Drop# 详细描述# Drop creates an array/slice with n
elements dropped from the beginning.
Drop(in any, n int) any
返回值# Equal# 详细描述# IsEqual returns if the two objects are equal
Equal(expected any, actual any) bool
参数名 参数类型 参数解释 expected any
actual any
返回值# Every# 详细描述# Every returns true if every element is present in a iteratee.
Every(in any, elements ...any) bool
参数名 参数类型 参数解释 in any
elements ...any
返回值# Filter# 详细描述# Filter(i any, fc func(any) bool) any
参数名 参数类型 参数解释 i any
fc func(any) bool
返回值# Find# 详细描述# Find(i any, fc func(any) bool) any
参数名 参数类型 参数解释 i any
fc func(any) bool
返回值# Foreach# 详细描述# Foreach(i any, fc func(any))
参数名 参数类型 参数解释 i any
fc func(any)
ForeachRight# 详细描述# ForeachRight(i any, fc func(any))
参数名 参数类型 参数解释 i any
fc func(any)
详细描述# GC()
GCPercent# 详细描述# SetGCPercent sets the garbage collection target percentage:
a collection is triggered when the ratio of freshly allocated data
to live data remaining after the previous collection reaches this percentage.
SetGCPercent returns the previous setting.
The initial setting is the value of the GOGC environment variable
at startup, or 100 if the variable is not set.
This setting may be effectively reduced in order to maintain a memory
limit.
A negative percentage effectively disables garbage collection, unless
the memory limit is reached.
See SetMemoryLimit for more details.
GCPercent(percent int) int
返回值# Head# 详细描述# Head gets the first element of array.
Head(arr any) any
返回值# 详细描述# If(i bool, a any, b any) any
返回值# IndexOf# 详细描述# IndexOf gets the index at which the first occurrence of value is found in array or return -1
if the value cannot be found
IndexOf(in any, elem any) int
返回值# Intersect# 详细描述# Intersect(x any, y any) any
返回值# IsSubset# 详细描述# Subset returns true if collection x is a subset of y.
IsSubset(x any, y any) bool
返回值# Keys# 详细描述# Keys creates an array of the own enumerable map keys or struct field names.
Keys(out any) any
返回值# Map# 详细描述# Map(i any, fc funkGeneralFuncType) any
参数名 参数类型 参数解释 i any
fc funkGeneralFuncType
返回值# Max# 详细描述# Max(i any) any
返回值# Min# 详细描述# Min(i any) any
返回值# Range# 详细描述# Range(i int) []any
返回值# Reduce# 详细描述# Reduce(i any, fc funkGeneralReduceFuncType, acc any) any
参数名 参数类型 参数解释 i any
fc funkGeneralReduceFuncType
acc any
返回值# RemoveRepeat# 详细描述# Uniq creates an array with unique values.
RemoveRepeat(in any) any
返回值# Retry# 详细描述# retry 对第二个参数作为函数的情况,重试N次,如果第二个参数返回值是 true,则重试,否则就结束,如果遇到错误,停止重试
Example:
count = 0
retry(100, () => { defer recover()
count++ if count > 3 { die(111) } return true })
assert count == 4, f`${count}`
count = 0
retry(100, () => { defer recover()
count++ if count > 3 { return false } return true })
assert count == 4, f`${count}`
count = 0
retry(100, () => { count++ })
assert count == 1, f`${count}`
count = 0
retry(100, () => { count++ return true })
assert count == 100, f`${count}`
Copy Retry(i int, handler func() bool)
参数名 参数类型 参数解释 i int
handler func() bool
Reverse# 详细描述# Reverse transforms an array the first element will become the last,
the second element will become the second to last, etc.
Reverse(in any) any
返回值# Shift# 详细描述# Shift(i any) any
返回值# Shuffle# 详细描述# Shuffle creates an array of shuffled values
Shuffle(in any) any
返回值# Some# 详细描述# Some returns true if atleast one element is present in an iteratee.
Some(in any, elements ...any) bool
参数名 参数类型 参数解释 in any
elements ...any
返回值# Sort# 详细描述# SliceStable sorts the slice x using the provided less
function, keeping equal elements in their original order.
It panics if x is not a slice.
The less function must satisfy the same requirements as
the Interface type's Less method.
Note: in many situations, the newer [slices.SortStableFunc] function is more
ergonomic and runs faster.
Sort(x any, less func(i, j int) bool)
参数名 参数类型 参数解释 x any
less func(i, j int) bool
Subtract# 详细描述# Subtract returns the subtraction between two collections.
Subtract(x any, y any) any
返回值# Sum# 详细描述# Sum computes the sum of the values in array.
Sum(arr any) float64
返回值# 返回值(顺序) 返回值类型 返回值解释 r1 float64
Tail# 详细描述# Tail gets all but the first element of array.
Tail(arr any) any
返回值# ToFloat64# 详细描述# ToFloat64 converts any numeric value to float64.
ToFloat64(x any) (float64, bool)
返回值# 返回值(顺序) 返回值类型 返回值解释 r1 float64
r2 bool
ToMap# 详细描述# ToMap transforms a slice of instances to a Map.
[]Foo => Map<int, Foo>
ToMap(in any, pivot string) any
参数名 参数类型 参数解释 in any
pivot string
返回值# Values# 详细描述# Values creates an array of the own enumerable map values or struct field values.
Values(out any) any
返回值# WaitConnect# 详细描述# WaitConnect 等待一个地址的端口开放或指导超时时间,如果超时则返回错误,这通常用于等待并确保一个服务启动
Example:
timeout, _ = time.ParseDuration("1m") ctx, cancel = context.WithTimeout(context.New(), timeout)
go func() { err = tcp.Serve("127.0.0.1", 8888, tcp.serverCallback(func (conn) { conn.Send("hello world") conn.Close() }), tcp.serverContext(ctx))
die(err) }()
os.WaitConnect("127.0.0.1:8888", 5)~ // 等待tcp服务器启动 conn = tcp.Connect("127.0.0.1", 8888)~ bytes = conn.Recv()~ println(string(bytes))
Copy WaitConnect(addr string, timeout float64) error
参数名 参数类型 参数解释 addr string
timeout float64
返回值# Zip# 详细描述# Zip returns a list of tuples, where the i-th tuple contains the i-th element
from each of the input iterables. The returned list is truncated in length
to the length of the shortest input iterable.
Zip(slice1 any, slice2 any) []Tuple
参数名 参数类型 参数解释 slice1 any
slice2 any
返回值# 返回值(顺序) 返回值类型 返回值解释 r1 []Tuple