unsafe

package
v0.0.0-...-d5aba35 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: MIT Imports: 7 Imported by: 0

README

An unsafe version that assumes enumerations always succeed.

DotNet LINQ may throws when it involves databases, multi-threading, await etc. In Go, database integration is not available yet. In most cases we just use FromSlice. So returning a error makes code unnecessarily complicated.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyEnumerable = errors.New(`IEnumerable is empty`)
)
View Source
var (
	ErrInvalidState = errors.New(`Invalid state`)
)

Functions

func Any

func Any[T any](q IEnumerable[T]) bool

func Average

func Average[T Number](q IEnumerable[T]) (result T)

func Contains

func Contains[T comparable](q IEnumerable[T], v T) bool

func Do

func Do[T any](q IEnumerable[T], f func(T))

Apply f() to all items in q

func First

func First[T any](source IEnumerable[T], ok *bool) T

func FirstWhere

func FirstWhere[T any](source IEnumerable[T], pred func(T) bool, found *bool) T

func Foreach

func Foreach[T any](q IEnumerable[T], f func(T) error) (err error)

Apply f() to all items in q, break when f() returns false

func ForeachI

func ForeachI[T any](q IEnumerable[T], f func(int, T) error) (err error)

Apply f() to all items in q, break when f() returns false. A counted index is passed to f()

func Last

func Last[T any](source IEnumerable[T], found *bool) T

func LastWhere

func LastWhere[T any](source IEnumerable[T], pred func(T) bool, retFound *bool) T

func Max

func Max[T constraints.Ordered](q IEnumerable[T]) (result T)

func MaxBy

func MaxBy[T any, K constraints.Ordered](q IEnumerable[T], selector func(T) K) (result T)

func Min

func Min[T constraints.Ordered](q IEnumerable[T]) (result T)

func MinBy

func MinBy[T any, K constraints.Ordered](q IEnumerable[T], selector func(T) K) (result T)

func Sum

func Sum[T Number](q IEnumerable[T]) (result T)

func ToMap

func ToMap[T any, K comparable, V any](
	me IEnumerable[T], keyFunc func(T) K, valFunc func(T) V) map[K]V

func ToSlice

func ToSlice[T any](me IEnumerable[T]) []T

Types

type ICount

type ICount[T any] interface {
	Count() int
}

type IEnumerable

type IEnumerable[T any] interface {
	GetEnumerator() IEnumerator[T]
	Count() int
	Any() bool
}

func Abs

func Abs[T Number](q IEnumerable[T]) IEnumerable[T]

func Clamp

func Clamp[T constraints.Ordered](q IEnumerable[T], min, max T) IEnumerable[T]

func FromMap

func FromMap[K comparable, V any](v map[K]V) IEnumerable[Pair[K, V]]

func FromMapCopy

func FromMapCopy[K comparable, V any](v map[K]V) IEnumerable[Pair[K, V]]

先复制出一个 []Pair[K,V],再转成 IEnumerable,不适用于map很大的情况

func FromMapReflect

func FromMapReflect[K comparable, V any](v map[K]V) IEnumerable[Pair[K, V]]

通过 reflect.MapRange 遍历 map,线性读取快,随机访问慢

func FromSlice

func FromSlice[T any](v []T) IEnumerable[T]

func Join

func Join[Outer, Inner, Result any](
	outer IEnumerable[Outer],
	inner IEnumerable[Inner],
	pred func(Outer, Inner) (selected bool, result Result)) IEnumerable[Result]

func Range

func Range[T constraints.Integer | constraints.Float](start, end T) IEnumerable[T]

func RangeStep

func RangeStep[T constraints.Integer | constraints.Float](start, end, step T) IEnumerable[T]

func Select

func Select[T any, T2 any](source IEnumerable[T], selector func(T) T2) IEnumerable[T2]

func Skip

func Skip[T any](source IEnumerable[T], n int) IEnumerable[T]

func Take

func Take[T any](source IEnumerable[T], n int) IEnumerable[T]

func Where

func Where[T any](source IEnumerable[T], pred func(T) bool) IEnumerable[T]

type IEnumerableAndEnumerator

type IEnumerableAndEnumerator[T any] interface {
	IEnumerable[T]
	IEnumerator[T]
}

type IEnumerator

type IEnumerator[T any] interface {
	Current() T
	MoveNext() bool
}

type IGetAt

type IGetAt[T any] interface {
	GetAt(i int) T
}

type IRangeEnumerator

type IRangeEnumerator[T any] interface {
	ICount[T]
	IGetAt[T]
	SeekOnce(i int) error // can only seek once
}

type JoinEnumerableIterator

type JoinEnumerableIterator[Outer, Inner, Result any] struct {
	// contains filtered or unexported fields
}

func NewJoinIterator

func NewJoinIterator[Outer, Inner, Result any](
	outer IEnumerable[Outer],
	inner IEnumerable[Inner],
	pred func(Outer, Inner) (selected bool, result Result)) *JoinEnumerableIterator[Outer, Inner, Result]

func (*JoinEnumerableIterator[Outer, Inner, Result]) Any

func (me *JoinEnumerableIterator[Outer, Inner, Result]) Any() bool

func (*JoinEnumerableIterator[Outer, Inner, Result]) Clone

func (me *JoinEnumerableIterator[Outer, Inner, Result]) Clone() IEnumerator[Result]

func (*JoinEnumerableIterator[Outer, Inner, Result]) Count

func (me *JoinEnumerableIterator[Outer, Inner, Result]) Count() int

func (*JoinEnumerableIterator) Current

func (me *JoinEnumerableIterator) Current() T

func (*JoinEnumerableIterator) GetEnumerator

func (me *JoinEnumerableIterator) GetEnumerator() IEnumerator[T]

func (*JoinEnumerableIterator[Outer, Inner, Result]) MoveNext

func (me *JoinEnumerableIterator[Outer, Inner, Result]) MoveNext() bool

type Map

type Map[K comparable, V any] map[K]V

func (Map[K, V]) Any

func (me Map[K, V]) Any() bool

func (Map[K, V]) Count

func (me Map[K, V]) Count() int

func (Map[K, V]) GetEnumerator

func (me Map[K, V]) GetEnumerator() IEnumerator[Pair[K, V]]

type MapEnumerator

type MapEnumerator[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func (*MapEnumerator[K, V]) Current

func (me *MapEnumerator[K, V]) Current() Pair[K, V]

func (*MapEnumerator[K, V]) MoveNext

func (me *MapEnumerator[K, V]) MoveNext() bool

func (*MapEnumerator[K, V]) Reset

func (me *MapEnumerator[K, V]) Reset() error

type Number

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

type OrderIterator

type OrderIterator[T any] struct {
	// contains filtered or unexported fields
}

func (*OrderIterator) Current

func (me *OrderIterator) Current() T

func (*OrderIterator) GetEnumerator

func (me *OrderIterator) GetEnumerator() IEnumerator[T]

func (*OrderIterator) MoveNext

func (me *OrderIterator) MoveNext() error

type Pair

type Pair[K comparable, V any] struct {
	Key   K
	Value V
}

type RangeIterator

type RangeIterator[T constraints.Integer | constraints.Float] struct {
	// contains filtered or unexported fields
}

func NewRangeIterator

func NewRangeIterator[T constraints.Integer | constraints.Float](start, end, step T) *RangeIterator[T]

func (*RangeIterator[T]) Any

func (me *RangeIterator[T]) Any() bool

func (*RangeIterator[T]) Clone

func (me *RangeIterator[T]) Clone() IEnumerator[T]

func (*RangeIterator[T]) Count

func (me *RangeIterator[T]) Count() int

func (*RangeIterator) Current

func (me *RangeIterator) Current() T

func (*RangeIterator[T]) GetAt

func (me *RangeIterator[T]) GetAt(pos int) (result T, err error)

func (*RangeIterator) GetEnumerator

func (me *RangeIterator) GetEnumerator() IEnumerator[T]

func (*RangeIterator[T]) MoveNext

func (me *RangeIterator[T]) MoveNext() bool

func (*RangeIterator[T]) SeekOnce

func (me *RangeIterator[T]) SeekOnce(pos int) error

type SelectEnumerableIterator

type SelectEnumerableIterator[T any, T2 any] struct {
	// contains filtered or unexported fields
}

func NewSelectIterator

func NewSelectIterator[T any, T2 any](source IEnumerable[T], selector func(T) T2) *SelectEnumerableIterator[T, T2]

func (*SelectEnumerableIterator[T, T2]) Any

func (me *SelectEnumerableIterator[T, T2]) Any() bool

func (*SelectEnumerableIterator[T, T2]) Clone

func (me *SelectEnumerableIterator[T, T2]) Clone() IEnumerator[T2]

func (*SelectEnumerableIterator[T, T2]) Count

func (me *SelectEnumerableIterator[T, T2]) Count() int

func (*SelectEnumerableIterator) Current

func (me *SelectEnumerableIterator) Current() T

func (*SelectEnumerableIterator) GetEnumerator

func (me *SelectEnumerableIterator) GetEnumerator() IEnumerator[T]

func (*SelectEnumerableIterator[T, T2]) MoveNext

func (me *SelectEnumerableIterator[T, T2]) MoveNext() bool

type SkipIterator

type SkipIterator[T any] struct {
	// contains filtered or unexported fields
}

func NewSkipIterator

func NewSkipIterator[T any](source IEnumerable[T], n int) *SkipIterator[T]

func (*SkipIterator[T]) Any

func (me *SkipIterator[T]) Any() bool

func (*SkipIterator[T]) Clone

func (me *SkipIterator[T]) Clone() IEnumerator[T]

func (*SkipIterator[T]) Count

func (me *SkipIterator[T]) Count() int

func (*SkipIterator) Current

func (me *SkipIterator) Current() T

func (*SkipIterator) GetEnumerator

func (me *SkipIterator) GetEnumerator() IEnumerator[T]

func (*SkipIterator[T]) MoveNext

func (me *SkipIterator[T]) MoveNext() bool

type Slice

type Slice[T any] []T

func (Slice[T]) Any

func (me Slice[T]) Any() bool

func (Slice[T]) Count

func (me Slice[T]) Count() int

func (Slice[T]) GetAt

func (me Slice[T]) GetAt(i int) (v T)

func (Slice[T]) GetEnumerator

func (me Slice[T]) GetEnumerator() IEnumerator[T]

type SliceEnumerator

type SliceEnumerator[T any] struct {
	// contains filtered or unexported fields
}

func (*SliceEnumerator[T]) Count

func (me *SliceEnumerator[T]) Count() int

func (*SliceEnumerator[T]) Current

func (me *SliceEnumerator[T]) Current() T

func (*SliceEnumerator[T]) GetAt

func (me *SliceEnumerator[T]) GetAt(pos int) (v T)

func (*SliceEnumerator[T]) MoveNext

func (me *SliceEnumerator[T]) MoveNext() bool

func (*SliceEnumerator[T]) Reset

func (me *SliceEnumerator[T]) Reset() error

func (*SliceEnumerator[T]) SeekOnce

func (me *SliceEnumerator[T]) SeekOnce(pos int) error

type TakeIterator

type TakeIterator[T any] struct {
	// contains filtered or unexported fields
}

func NewTakeIterator

func NewTakeIterator[T any](source IEnumerable[T], n int) *TakeIterator[T]

func (*TakeIterator[T]) Any

func (me *TakeIterator[T]) Any() bool

func (*TakeIterator[T]) Clone

func (me *TakeIterator[T]) Clone() IEnumerator[T]

func (*TakeIterator[T]) Count

func (me *TakeIterator[T]) Count() int

func (*TakeIterator) Current

func (me *TakeIterator) Current() T

func (*TakeIterator) GetEnumerator

func (me *TakeIterator) GetEnumerator() IEnumerator[T]

func (*TakeIterator[T]) MoveNext

func (me *TakeIterator[T]) MoveNext() bool

type WhereEnumerableIterator

type WhereEnumerableIterator[T any] struct {
	// contains filtered or unexported fields
}

func NewWhereIterator

func NewWhereIterator[T any](source IEnumerable[T], pred func(T) bool) *WhereEnumerableIterator[T]

func (*WhereEnumerableIterator[T]) Any

func (me *WhereEnumerableIterator[T]) Any() bool

func (*WhereEnumerableIterator[T]) Clone

func (me *WhereEnumerableIterator[T]) Clone() IEnumerator[T]

func (*WhereEnumerableIterator[T]) Count

func (me *WhereEnumerableIterator[T]) Count() int

func (*WhereEnumerableIterator) Current

func (me *WhereEnumerableIterator) Current() T

func (*WhereEnumerableIterator) GetEnumerator

func (me *WhereEnumerableIterator) GetEnumerator() IEnumerator[T]

func (*WhereEnumerableIterator[T]) MoveNext

func (me *WhereEnumerableIterator[T]) MoveNext() bool

Jump to

Keyboard shortcuts

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