linq

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: MIT Imports: 3 Imported by: 0

README

Linq-like syntax for Golang.

Go Version GoDoc Build Status Go report Coverage License

Install

go get github.com/fangpin/linq

Supported linq operation

  • aggregate
  • all
  • any
  • average
  • chunk
  • contains
  • count
  • default_if_empty
  • distinct
  • distinct_by
  • except
  • except_by
  • first
  • first_or_default
  • group_by
  • group_join
  • intersect
  • intersect_by
  • keys
  • last
  • last_or_default
  • max
  • max_by
  • min
  • min_by
  • of_type
  • order
  • order_by
  • order_by_descending
  • order_descending
  • prepend
  • repeat
  • reverse
  • select
  • select_many
  • single
  • single_or_default
  • skip
  • skip_last
  • skip_while
  • sum
  • take
  • take_last
  • take_while
  • to_dictionary
  • to_hash_set
  • to_lookup
  • union
  • union_by
  • values
  • where
  • zero
  • zip

Documentation

Overview

Package linq defines a set of useful linq to be used with type parameters.

Index

Constants

View Source
const (
	ElementNotFound      string = "element not found"
	MultipleElementFound string = "multiple element found"
	EmptySource          string = "empty source"
	InvalidParam         string = "Invalid parameter"
)

Variables

This section is empty.

Functions

func Aggregate

func Aggregate[T any](source []T, initial T, f func(agg, now T) T) T

func All

func All[T any](source []T, predicator func(x T) bool) bool

func Any

func Any[T any](source []T, predicator func(x T) bool) bool

func Average

func Average[T Number](source []T) float64

func Chunk

func Chunk[T any](source []T, size int) [][]T

func Contains

func Contains[T comparable](source []T, key T) bool

func Count

func Count[T any](source []T, f func(x T) bool) int

func DefaultIfEmpty

func DefaultIfEmpty[T any](source []T) []T

func Distinct

func Distinct[T comparable](source []T) []T

func DistinctBy

func DistinctBy[T any, R comparable](source []T, f func(x T) R) []T

func Except

func Except[T comparable](l []T, r []T) []T

func ExceptBy

func ExceptBy[T any, R comparable](source []T, keys []R, f func(x T) R) []T

func First

func First[T any](source []T, f func(x T) bool) T

func FirstOrDefault

func FirstOrDefault[T any](source []T, pred func(x T) bool) T

func GroupBy

func GroupBy[T any, R comparable, S any](source []T, keyGen func(x T) R, groupSelector func([]T) S) map[R]S

func GroupJoin

func GroupJoin[T, R, S any, K comparable](
	outter []T,
	inner []R,
	outterKeySelector func(T) K,
	innerKeySelector func(R) K,
	resultSelector func(T, []R) S) []S

func Intersect

func Intersect[T comparable](l, r []T) []T

func IntersectBy

func IntersectBy[T any, K comparable](source []T, keys []K, keyGen func(x T) K) []T

func Keys

func Keys[T comparable, R any](source map[T]R) []T

func Last

func Last[T comparable](source []T, predictor func(x T) bool) T

func LastOrDefault

func LastOrDefault[T comparable](source []T, predictor func(x T) bool) T

func Max

func Max[T constraints.Ordered](source []T) T

func MaxBy

func MaxBy[T any, K constraints.Ordered](source []T, com func(x T) K) T

func Min

func Min[T constraints.Ordered](source []T) T

func MinBy

func MinBy[T any, K constraints.Ordered](source []T, com func(x T) K) T

func OfType

func OfType(source []any, expectType reflect.Type) []any

func Order

func Order[T constraints.Ordered](source []T) []T

func OrderBy

func OrderBy[T constraints.Ordered](source []T, comparer func(l, r T) bool) []T

func OrderByDescending

func OrderByDescending[T constraints.Ordered](source []T, comparer func(l, r T) bool) []T

func OrderDescending

func OrderDescending[T constraints.Ordered](source []T) []T

func Prepend

func Prepend[T any](source []T, target ...T) []T

func Repeat

func Repeat[T any](element T, times uint) []T

func Reverse

func Reverse[T any](source []T) (target []T)

func Select

func Select[T, R any](source []T, f func(x T) R) []R

func SelectMany

func SelectMany[T, R any](source []T, manySelector func(x T) []R) []R

func Single

func Single[T comparable](source []T, pred func(x T) bool) T

func SingleOrDefault

func SingleOrDefault[T comparable](source []T, pred func(x T) bool) T

func Skip

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

func SkipLast

func SkipLast[T any](source []T, count int) []T

func SkipWhile

func SkipWhile[T any](source []T, skipCond func(x T) bool) []T

func Sum

func Sum[T Number](source []T) T

func Take

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

func TakeLast

func TakeLast[T any](source []T, n int) []T

func TakeWhile

func TakeWhile[T any](source []T, takeCond func(x T) bool) []T

func ToDictionary

func ToDictionary[T any, K comparable](source []T, keyGen func(x T) K) map[K]T

func ToHashSet

func ToHashSet[T comparable](source []T) map[T]struct{}

func ToLookUp

func ToLookUp[T, R any, K comparable](source []T, keySelector func(x T) K, elementSelector func(x T) R) map[K]R

func Union

func Union[T comparable](left, right []T) []T

func UnionBy

func UnionBy[T any, K comparable](left, right []T, keySelector func(x T) K) []T

func Values

func Values[T comparable, R any](source map[T]R) []R

func Where

func Where[T any](source []T, f func(x T) bool) []T

Types

type Complex

type Complex interface {
	~complex64 | ~complex128
}

Complex is a constraint that permits any complex numeric type. If future releases of Go add new predeclared complex numeric types, this constraint will be modified to include them.

type Float

type Float interface {
	~float32 | ~float64
}

Float is a constraint that permits any floating-point type. If future releases of Go add new predeclared floating-point types, this constraint will be modified to include them.

type Integer

type Integer interface {
	Signed | Unsigned
}

Integer is a constraint that permits any integer type. If future releases of Go add new predeclared integer types, this constraint will be modified to include them.

type Number

type Number interface {
	Float | Integer
}

type Ordered

type Ordered interface {
	Integer | Float | ~string
}

Ordered is a constraint that permits any ordered type: any type that supports the operators < <= >= >. If future releases of Go add new ordered types, this constraint will be modified to include them.

type Pair

type Pair[T, R any] struct {
	First  T
	Second R
}

func Zip

func Zip[T, R any](left []T, right []R) []Pair[T, R]

type Signed

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

Signed is a constraint that permits any signed integer type. If future releases of Go add new predeclared signed integer types, this constraint will be modified to include them.

type Unsigned

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

Unsigned is a constraint that permits any unsigned integer type. If future releases of Go add new predeclared unsigned integer types, this constraint will be modified to include them.

Jump to

Keyboard shortcuts

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