a

package module
v0.0.0-...-3b5a5f8 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: MIT Imports: 4 Imported by: 0

README

a

Go License_MIT

Abstruct

The a package is simple Go utilities for collection operation. This is inspired by the language integrated query (LINQ) in .NET Framework. This does not contain a struct/interface equivalent to the Enumerable class or the IEnumerable interface, so deferred execution using the iterator pattern is not possible.

Currently implemented
  • AggregateSelect
    • the original function
  • AggregateSelectWithIndex
    • the original function
  • All
  • Any
  • Chunk
  • ChunkWithErr
  • Contains
  • Distinct
  • DistinctBy
  • DistinctByWithErr
  • Filters
    • the original function
    • Filters() returns results corresponding to filters and the unfiltered result.
  • FirstOrDefault
  • GroupBy
  • GroupByWithErr
  • LastOrDefault
  • MaxBy
  • MaxByWithErr
  • MinBy
  • MinByWithErr
  • OrderBy
  • OrderByWithErr
  • OrderByDescending
  • OrderByDescendingWithErr
  • Select
  • SelectWithErr
  • SelectMany
  • Sum
  • SumWithErr
  • ToMap
    • as an alternative to ToDictionary
  • ToMapWithErr
  • Where
  • WhereSelect
    • the original function
    • WhereSelect() is convenient when using Where() and Select() at the same time.
  • WhereSelectWithErr
Todo
  • Doc
  • Implement
    • Aggregate
    • AsEnumerable
    • Average
    • Cast
    • Concat
    • Count
    • DefaultIfEmpty
    • ElementAt
    • ElementAtOrDefault
    • Empty
    • Except
    • ExceptBy
    • First
    • GroupJoin
    • Intersect
    • IntersectBy
    • Join
    • Last
    • LongCount
    • Max
    • Min
    • OfType
    • Order
    • OrderDescending
    • Prepend
    • Range
    • Repeat
    • Reverse
    • SequenceEqual
    • Single
    • SingleOrDefault
    • Skip
    • SkipLast
    • SkipWhile
    • Sum
      • for only number slice
    • Take
    • TakeLast
    • TakeWhile
    • ThenBy
    • ThenByDescending
    • ToArray
    • ToHashSet
    • ToList
    • ToLookup
    • TryGetNonEnumeratedCount
    • Union
    • UnionBy
    • Zip
  • Test
    • ToMap
    • WhereSelect
Tests
  • How to measure code coverage
    • go test -cover ./...
  • How to find not covered lines of code
    • go test -cover ./... -coverprofile=cover.out
    • go tool cover -html=cover.out -o cover.html
    • see cover.html

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrArg error = errors.New("argument error")
View Source
var ErrDuplicateKeyValue error = errors.New("duplicate key value error")

Functions

func AggregateSelect

func AggregateSelect[T, S any](src []T, initialF func(T) S, f func(S, T) S) S

func AggregateSelectWithIndex

func AggregateSelectWithIndex[T, S any](src []T, initialF func(T) S, f func(S, T, int) S) S

func All

func All[T any](src []T, a func(T) bool) bool

func Any

func Any[T any](src []T, a func(T) bool) bool

func Chunk

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

func ChunkWithErr

func ChunkWithErr[T any](src []T, size int) ([][]T, error)

func Contains

func Contains[T comparable](src []T, e T) bool

func Distinct

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

func DistinctBy

func DistinctBy[T any, K comparable](src []T, d func(T) K) []T

func DistinctByWithErr

func DistinctByWithErr[T any, K comparable](src []T, d func(T) K) ([]T, error)

func Filters

func Filters[T any](src []T, fs ...func(T) bool) ([][]T, []T)

func FirstOrDefault

func FirstOrDefault[T any](src []T) T

func GroupBy

func GroupBy[K comparable, T any](src []T, k func(T) K) map[K][]T

func GroupByWithErr

func GroupByWithErr[K comparable, T any](src []T, k func(T) K) (map[K][]T, error)

func LastOrDefault

func LastOrDefault[T any](src []T) T

func MaxBy

func MaxBy[T any, S cmp.Ordered](src []T, m func(T) S) T

func MaxByWithErr

func MaxByWithErr[T any, S cmp.Ordered](src []T, m func(T) S) (T, error)

func MinBy

func MinBy[T any, S cmp.Ordered](src []T, m func(T) S) T

func MinByWithErr

func MinByWithErr[T any, S cmp.Ordered](src []T, m func(T) S) (T, error)

func OrderBy

func OrderBy[T any, S cmp.Ordered](src []T, o func(T) S) []T

func OrderByDescending

func OrderByDescending[T any, S cmp.Ordered](src []T, o func(T) S) []T

func OrderByDescendingWithErr

func OrderByDescendingWithErr[T any, S cmp.Ordered](src []T, o func(T) S) ([]T, error)

func OrderByWithErr

func OrderByWithErr[T any, S cmp.Ordered](src []T, o func(T) S) ([]T, error)

func Select

func Select[T, S any](src []T, s func(T) S) []S

func SelectMany

func SelectMany[T, S any](src []T, s func(T) []S) []S

func SelectWithErr

func SelectWithErr[T, S any](src []T, s func(T) S) ([]S, error)

func Sum

func Sum[T any, S number](src []T, s func(T) S) S

func SumWithErr

func SumWithErr[T any, S number](src []T, s func(T) S) (S, error)

func ToMap

func ToMap[K comparable, T any](src []T, k func(T) K) map[K]T

func ToMapWithErr

func ToMapWithErr[K comparable, T any](src []T, k func(T) K) (map[K]T, error)

func Where

func Where[T any](src []T, w func(T) bool) []T

func WhereSelect

func WhereSelect[T, S any](src []T, w func(T) bool, s func(T) S) []S

func WhereSelectWithErr

func WhereSelectWithErr[T, S any](src []T, w func(T) bool, s func(T) S) ([]S, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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