Documentation ¶
Overview ¶
Package ysq ...
Index ¶
- Variables
- func CastToString[T any]() func(T) string
- func NumberComparer[T constraints.Integer | constraints.Float](prev, current T) int
- func Reduce[T, TResult any](q *Query[T], initializer TResult, f delegate.Func2[TResult, T, TResult]) TResult
- func Sum[T any, R constraints.Integer | constraints.Float](q *Query[T], selector func(T) R) R
- func ToMap[T any, TKey comparable](q *Query[T], keySelector delegate.Func1[T, TKey]) map[TKey]T
- type ChanResult
- type Comparable
- type Comparer
- type GetHashCoder
- type IterContinue
- type Iterable
- type Iterator
- type KeyListPair
- type KeyValuePair
- type Query
- func Cast[T, TResult any](q *Query[T], caster func(T) TResult) *Query[TResult]
- func FromChan[T any](c chan T) *Query[T]
- func FromElement[T any](source ...T) *Query[T]
- func FromMap[K comparable, V any](m map[K]V) *Query[KeyValuePair[K, V]]
- func FromSequence[T constraints.Integer](start, end T, stepE ...int) *Query[T]
- func FromSequenceChan[T constraints.Integer](start, end T, stepE ...int) *Query[T]
- func FromSlice[T any](source []T) *Query[T]
- func FromString(s string) *Query[rune]
- func GroupBy[T any, TKey comparable](q *Query[T], keySelector func(T) TKey) *Query[KeyListPair[TKey, T]]
- func GroupByWithC[T any, TKey comparable, TResult any](q *Query[T], keySelector func(T) TKey, resultSelector func(TKey, []T) TResult) *Query[KeyValuePair[TKey, TResult]]
- func Select[T, TResult any](q *Query[T], selector func(T) TResult) *Query[TResult]
- func SelectMany[T, TResult any](q *Query[T], selector func(T) *Query[TResult]) *Query[TResult]
- func Zip[T, TSecond, TResult any](q *Query[T], list []TSecond, resultSelector func(T, TSecond) TResult) *Query[TResult]
- func ZipQ[T, TSecond, TResult any](q *Query[T], qs *Query[TSecond], resultSelector func(T, TSecond) TResult) *Query[TResult]
- func (q *Query[T]) All(predicate delegate.FuncTBool[T]) bool
- func (q *Query[T]) Any() bool
- func (q *Query[T]) CastToInt32By(caster func(T) int32) *Query[int32]
- func (q *Query[T]) CastToInt64By(caster func(T) int64) *Query[int64]
- func (q *Query[T]) CastToIntBy(caster func(T) int) *Query[int]
- func (q *Query[T]) CastToInterface() *Query[interface{}]
- func (q *Query[T]) CastToStringBy(caster func(T) string) *Query[string]
- func (q *Query[T]) Contains(predicate delegate.FuncTBool[T]) bool
- func (q *Query[T]) Count() int64
- func (q *Query[T]) CountBy(predicate delegate.FuncTBool[T]) int64
- func (q *Query[T]) Distinct() *Query[T]
- func (q *Query[T]) DistinctBy(getter GetHashCoder[T]) *Query[T]
- func (q *Query[T]) ElementAt(index int) (T, error)
- func (q *Query[T]) ElementAtOr(index int, source T) T
- func (q *Query[T]) Except(other []T) *Query[T]
- func (q *Query[T]) ExceptQ(otherQ *Query[T]) *Query[T]
- func (q *Query[T]) ExpectBy(other []T, getter GetHashCoder[T]) *Query[T]
- func (q *Query[T]) Filter(predicate delegate.FuncTBool[T]) *Query[T]
- func (q *Query[T]) FilterN(predicate delegate.FuncTIntBool[T]) *Query[T]
- func (q *Query[T]) First() (T, error)
- func (q *Query[T]) FirstBy(predicate delegate.FuncTBool[T]) (T, error)
- func (q *Query[T]) FirstOr(v T) T
- func (q *Query[T]) FirstOrBy(v T, predicate delegate.FuncTBool[T]) T
- func (q *Query[T]) ForEach(action delegate.Action1[T])
- func (q *Query[T]) ForEachE(f delegate.Func1[T, error]) (err error)
- func (q *Query[T]) ForEachEN(f delegate.Func2[T, int, error]) (err error)
- func (q *Query[T]) ForEachN(action delegate.Action2[T, int])
- func (q *Query[T]) ForEachx(action delegate.FuncTBool[T])
- func (q *Query[T]) ForEachxN(action delegate.FuncTIntBool[T])
- func (q *Query[T]) In(predicate delegate.FuncTBool[T]) bool
- func (q *Query[T]) Intersect(other []T) *Query[T]
- func (q *Query[T]) IntersectBy(other []T, getter GetHashCoder[T]) *Query[T]
- func (q *Query[T]) IntersectQ(otherQ *Query[T]) *Query[T]
- func (q *Query[T]) IsEmpty() bool
- func (q *Query[T]) Iter(next Iterator[T], predicate func(T) IterContinue) (item T, ok bool)
- func (q *Query[T]) Max(comparer Comparer[T]) T
- func (q *Query[T]) Min(comparer Comparer[T]) T
- func (q *Query[T]) Reduce(initializer T, f delegate.Func2[T, T, T]) T
- func (q *Query[T]) Reverse(sliceCap ...int) *Query[T]
- func (q *Query[T]) Select(selector func(T) T) *Query[T]
- func (q *Query[T]) Skip(cnt int) *Query[T]
- func (q *Query[T]) SkipWhile(predicate delegate.FuncTBool[T]) *Query[T]
- func (q *Query[T]) SumToFloat64(selector func(T) float64) float64
- func (q *Query[T]) SumToInt(selector func(T) int) int
- func (q *Query[T]) SumToInt32(selector func(T) int32) int32
- func (q *Query[T]) SumToInt64(selector func(T) int64) int64
- func (q *Query[T]) Take(cnt uint) *Query[T]
- func (q *Query[T]) TakeWhile(predicate delegate.FuncTBool[T]) *Query[T]
- func (q *Query[T]) TakeWhileN(predicate delegate.FuncTIntBool[T]) *Query[T]
- func (q *Query[T]) ToChan(cr *ChanResult[T])
- func (q *Query[T]) ToSet(sliceCap ...int) []T
- func (q *Query[T]) ToSlice(sliceCap ...int) []T
- func (q *Query[T]) Union(other []T) *Query[T]
- func (q *Query[T]) UnionBy(other []T, getter GetHashCoder[T]) *Query[T]
- func (q *Query[T]) UnionQ(otherQ *Query[T]) *Query[T]
- func (q *Query[T]) Where(predicate delegate.FuncTBool[T]) *Query[T]
- func (q *Query[T]) WhereN(predicate delegate.FuncTIntBool[T]) *Query[T]
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDataNotfound 数据未找到 ErrDataNotfound = errors.New(`not found`) )
Functions ¶
func NumberComparer ¶
func NumberComparer[T constraints.Integer | constraints.Float](prev, current T) int
NumberComparer ...
func Reduce ¶
func Reduce[T, TResult any](q *Query[T], initializer TResult, f delegate.Func2[TResult, T, TResult]) TResult
Reduce reduces a []T1 to a single value using a reduction function.
func Sum ¶
func Sum[T any, R constraints.Integer | constraints.Float](q *Query[T], selector func(T) R) R
Sum ...
Types ¶
type ChanResult ¶
ChanResult ...
func (*ChanResult[T]) CloseWithTimeout ¶
func (cr *ChanResult[T]) CloseWithTimeout(ts ...time.Duration)
CloseWithTimeout 带超时设定的关闭channel
func (*ChanResult[T]) GetWaitClose ¶
func (cr *ChanResult[T]) GetWaitClose() bool
GetWaitClose 获取关闭标识位
func (*ChanResult[T]) SetWaitClose ¶
func (cr *ChanResult[T]) SetWaitClose(v bool)
SetWaitClose 设置关闭标识位
type Query ¶
type Query[T any] struct { Next func() Iterator[T] }
Query 查询器
func Cast ¶
func Cast[T, TResult any](q *Query[T], caster func(T) TResult) *Query[TResult]
Cast 类型转换
func FromMap ¶
func FromMap[K comparable, V any](m map[K]V) *Query[KeyValuePair[K, V]]
FromMap map -> Query
func FromSequence ¶
func FromSequence[T constraints.Integer](start, end T, stepE ...int) *Query[T]
FromSequence sequence -> Query [start, end)
func FromSequenceChan ¶
func FromSequenceChan[T constraints.Integer](start, end T, stepE ...int) *Query[T]
FromSequenceChan sequence chan -> Query [start, end)
func GroupBy ¶
func GroupBy[T any, TKey comparable]( q *Query[T], keySelector func(T) TKey, ) *Query[KeyListPair[TKey, T]]
GroupBy 分组归类,不统计
func GroupByWithC ¶
func GroupByWithC[T any, TKey comparable, TResult any]( q *Query[T], keySelector func(T) TKey, resultSelector func(TKey, []T) TResult, ) *Query[KeyValuePair[TKey, TResult]]
GroupByWithC 根据自定义逻辑分组统计
func Select ¶
func Select[T, TResult any](q *Query[T], selector func(T) TResult) *Query[TResult]
Select 将序列中的每个元素投影到新表单
func SelectMany ¶
func SelectMany[T, TResult any](q *Query[T], selector func(T) *Query[TResult]) *Query[TResult]
SelectMany 将序列的每个元素投影并将结果序列合并为一个序列
func Zip ¶
func Zip[T, TSecond, TResult any]( q *Query[T], list []TSecond, resultSelector func(T, TSecond) TResult, ) *Query[TResult]
Zip 将指定函数应用于两个序列的对应元素,以生成结果序列
func ZipQ ¶
func ZipQ[T, TSecond, TResult any]( q *Query[T], qs *Query[TSecond], resultSelector func(T, TSecond) TResult, ) *Query[TResult]
ZipQ 将指定函数应用于两个序列的对应元素,以生成结果序列
func (*Query[T]) CastToInt32By ¶
CastToInt32By 转int32
func (*Query[T]) CastToInt64By ¶
CastToInt64By 转int64
func (*Query[T]) CastToIntBy ¶
CastToIntBy 转int
func (*Query[T]) CastToInterface ¶
func (q *Query[T]) CastToInterface() *Query[interface{}]
CastToInterface 转interface{}
func (*Query[T]) CastToStringBy ¶
CastToStringBy 转string
func (*Query[T]) DistinctBy ¶
func (q *Query[T]) DistinctBy(getter GetHashCoder[T]) *Query[T]
DistinctBy 有条件去重
func (*Query[T]) ElementAtOr ¶
func (q *Query[T]) ElementAtOr(index int, source T) T
ElementAtOr 返回序列中指定索引处的元素;如果索引超出范围,则返回默认值
func (*Query[T]) ExpectBy ¶
func (q *Query[T]) ExpectBy(other []T, getter GetHashCoder[T]) *Query[T]
ExpectBy 生成两个序列的差集
func (*Query[T]) FilterN ¶
func (q *Query[T]) FilterN(predicate delegate.FuncTIntBool[T]) *Query[T]
FilterN alias WhereN
func (*Query[T]) ForEachxN ¶
func (q *Query[T]) ForEachxN(action delegate.FuncTIntBool[T])
ForEachxN 可中断的遍历,带数字
func (*Query[T]) IntersectBy ¶
func (q *Query[T]) IntersectBy(other []T, getter GetHashCoder[T]) *Query[T]
IntersectBy 生成两个序列的交集
func (*Query[T]) IntersectQ ¶
func (q *Query[T]) IntersectQ(otherQ *Query[T]) *Query[T]
IntersectQ 生成两个序列的交集
func (*Query[T]) Iter ¶
func (q *Query[T]) Iter(next Iterator[T], predicate func(T) IterContinue) (item T, ok bool)
Iter 迭代
func (*Query[T]) Select ¶
func (q *Query[T]) Select(selector func(T) T) *Query[T]
Select 将序列中的每个元素投影到新表单
func (*Query[T]) SumToFloat64 ¶
SumToFloat64 ...
func (*Query[T]) SumToInt32 ¶
SumToInt32 ...
func (*Query[T]) SumToInt64 ¶
SumToInt64 ...
func (*Query[T]) TakeWhileN ¶
func (q *Query[T]) TakeWhileN(predicate delegate.FuncTIntBool[T]) *Query[T]
TakeWhileN 只要指定的条件为 true,就会返回序列的元素。将在谓词函数的逻辑中使用元素的索引
func (*Query[T]) UnionBy ¶
func (q *Query[T]) UnionBy(other []T, getter GetHashCoder[T]) *Query[T]
UnionBy 生成两个序列的并集
func (*Query[T]) WhereN ¶
func (q *Query[T]) WhereN(predicate delegate.FuncTIntBool[T]) *Query[T]
WhereN 基于谓词筛选值序列。 将在谓词函数的逻辑中使用每个元素的索引