Documentation
¶
Index ¶
- func AddUnique[ID comparable, T Identifiable[ID]](list []*T, newList []*T) []*T
- func All[T any](collection []T, predicate func(T) bool) booldeprecated
- func Any[T any](collection []T, predicate func(T) bool) booldeprecated
- func Clone[ID comparable, T any](m map[ID]*T) map[ID]*T
- func CloneRef[T any](r *T) *T
- func Contains[ID comparable](ids []ID, id ID) bool
- func CopyURL(u *url.URL) *url.URL
- func DR[A, B any](a A, _ B) A
- func Deref[T any](list []*T, skipNil bool) []T
- func DerefSlice[T any](collection []*T) []T
- func ExtractIDs[ID comparable, T Identifiable[ID]](list []*T) []ID
- func ExtractKeys[ID comparable, T any](m map[ID]*T) []ID
- func Filter[T any](collection []T, iteratee func(v T) bool) []T
- func FilterMap[T any, V any](collection []T, iteratee func(v T) *V) []V
- func FilterMapOk[T any, V any](collection []T, iteratee func(v T) (V, bool)) []Vdeprecated
- func FilterMapR[T any, V any](collection []T, iteratee func(v T) *V) []*V
- func Find[ID comparable, T Identifiable[ID]](list []*T, lid ID) *T
- func Get[ID comparable, T any](list []*T, getId func(*T) ID, id ID) *T
- func HasDuplicates[T comparable](collection []T) booldeprecated
- func IndexOf[ID comparable, T any](list []*T, getId func(*T) ID, id ID) int
- func Last[T any](list []*T) *T
- func ListClone[T any](list []T, getClone func(T) T) []T
- func ListFilter[ID comparable, T any](list []T, id ID, getId func(T) ID) []T
- func ListHas[ID comparable, T any](list []*T, getId func(*T) ID, id ID) bool
- func ListMap[ID comparable, T Identifiable[ID]](list []*T) map[ID]*T
- func ListMerge[T comparable](list []T, list2 []T, getClone func(T) T, duplicateSkip bool) []T
- func Map[T any, V any](collection []T, iteratee func(v T) V) []V
- func MapAdd[ID comparable, T Identifiable[ID]](m map[ID]*T, items ...*T) map[ID]*T
- func MapError[T comparable](t T, err error) func(m func(error) error) (T, error)
- func MapList[ID comparable, T any](m map[ID]*T, skipNil bool) []*T
- func MapPick[ID comparable, T Identifiable[ID]](m map[ID]*T, idList IDLister[ID]) []*T
- func MapWithIDFunc[ID comparable, T any](list []*T, idFunc func(*T) ID, checkNil bool) map[ID]*T
- func Merge[ID comparable, T Identifiable[ID]](m map[ID]*T, m2 map[ID]*T) map[ID]*T
- func MockNow(t time.Time) func()
- func Now() time.Time
- func OrError[T comparable](t T, err error) (r T, _ error)
- func Pick[ID comparable, T Identifiable[ID]](list []*T, idList IDLister[ID]) []*T
- func Properties[ID comparable, T any](list []*T, getProperty func(*T) ID) []ID
- func Remove[ID comparable, T Identifiable[ID]](list []*T, idsToRemove ...ID) []*T
- func RemoveById[ID comparable, T any](list []*T, getId func(*T) ID, id ID) []*T
- func RemoveByIds[ID comparable, T any](list []*T, getId func(*T) ID, ids ...ID) []*T
- func SortedEntries[K constraints.Ordered, V any](m map[K]V) []lo.Entry[K, V]
- func Subset[T comparable](collection, subCollection []T) booldeprecated
- func ToGenericList[S any, T any](list []*S, converter Converter[S, T]) []*T
- func ToGenericListValue[S any, T any](list []S, converter ConverterValue[S, T]) []*T
- func ToPtrIfNotEmpty[T comparable](t T) *T
- func Try(tries ...func() error) error
- func TryFilterMap[T any, V any](collection []T, iteratee func(v T) (V, bool, error)) ([]V, error)
- func TryMap[T any, V any](collection []T, iteratee func(v T) (V, error)) ([]V, error)
- type Cache
- type Converter
- type ConverterValue
- type DiffResult
- type DiffUpdate
- type Element
- type IDLister
- type Identifiable
- type List
- func (l List[T]) Add(elements ...T) List[T]
- func (l List[T]) AddUniq(elements ...T) List[T]
- func (l List[T]) At(i int) *T
- func (l List[T]) Concat(m []T) List[T]
- func (l List[T]) Copy() List[T]
- func (l List[T]) Delete(elements ...T) List[T]
- func (l List[T]) DeleteAt(i int) List[T]
- func (l List[T]) Has(elements ...T) bool
- func (l List[T]) Index(e T) int
- func (l List[T]) Insert(i int, elements ...T) List[T]
- func (l List[T]) Intersect(m []T) List[T]
- func (l List[T]) Len() int
- func (l List[T]) Move(e T, to int) List[T]
- func (l List[T]) MoveAt(from, to int) List[T]
- func (l List[T]) Ref() *List[T]
- func (l List[T]) Refs() []*T
- func (l List[T]) Reverse() List[T]
- type LockMap
- type SyncMap
- func (m *SyncMap[K, V]) Clone() *SyncMap[K, V]
- func (m *SyncMap[K, V]) CountAll(f func(key K, value V) bool) (i int)
- func (m *SyncMap[K, V]) Delete(key K)
- func (m *SyncMap[K, V]) DeleteAll(key ...K)
- func (m *SyncMap[K, V]) Find(f func(key K, value V) bool) (v V)
- func (m *SyncMap[K, V]) FindAll(f func(key K, value V) bool) (v []V)
- func (m *SyncMap[K, V]) Keys() (l []K)
- func (m *SyncMap[K, V]) Len() (i int)
- func (m *SyncMap[K, V]) Load(key K) (vv V, _ bool)
- func (m *SyncMap[K, V]) LoadAll(keys ...K) (r []V)
- func (m *SyncMap[K, V]) LoadAndDelete(key K) (vv V, ok bool)
- func (m *SyncMap[K, V]) LoadOr(key K, o V) (res V)
- func (m *SyncMap[K, V]) LoadOrStore(key K, value V) (vv V, _ bool)
- func (m *SyncMap[K, V]) Map(f func(K, V) V) *SyncMap[K, V]
- func (m *SyncMap[K, V]) Merge(n *SyncMap[K, V])
- func (m *SyncMap[K, V]) Range(f func(key K, value V) bool)
- func (m *SyncMap[K, V]) Store(key K, value V)
- func (m *SyncMap[K, V]) StoreAll(entries map[K]V)
- func (m *SyncMap[K, V]) Unsync() map[K]V
- func (m *SyncMap[K, V]) Values() (l []V)
- type TimeNow
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddUnique ¶
func AddUnique[ID comparable, T Identifiable[ID]](list []*T, newList []*T) []*T
func All
deprecated
https://github.com/samber/lo/issues/54
Deprecated: use lo.EveryBy instead.
func Any
deprecated
https://github.com/samber/lo/issues/54
Deprecated: use lo.SomeBy instead.
func Clone ¶
func Clone[ID comparable, T any](m map[ID]*T) map[ID]*T
func Contains ¶
func Contains[ID comparable](ids []ID, id ID) bool
func DerefSlice ¶
func DerefSlice[T any](collection []*T) []T
DerefSlice drops nil elements in the slice and return a new slice with dereferenced elements.
func ExtractIDs ¶
func ExtractIDs[ID comparable, T Identifiable[ID]](list []*T) []ID
func ExtractKeys ¶
func ExtractKeys[ID comparable, T any](m map[ID]*T) []ID
func FilterMap ¶
FilterMap is similar to Map, but if the iteratee returns nil, that element will be omitted from the new slice.
func FilterMapOk
deprecated
func FilterMapR ¶
FilterMapR is similar to FilterMap, but if the return value of the iteratee is not nil, it is not dereferenced and is used as the value of the new element.
func Find ¶
func Find[ID comparable, T Identifiable[ID]](list []*T, lid ID) *T
func Get ¶
func Get[ID comparable, T any](list []*T, getId func(*T) ID, id ID) *T
func HasDuplicates
deprecated
func HasDuplicates[T comparable](collection []T) bool
HasDuplicates returns true if the array contains a duplicated element
Deprecated: use lo.FindDuplicated instead.
func IndexOf ¶
func IndexOf[ID comparable, T any](list []*T, getId func(*T) ID, id ID) int
func ListFilter ¶
func ListFilter[ID comparable, T any](list []T, id ID, getId func(T) ID) []T
func ListHas ¶
func ListHas[ID comparable, T any](list []*T, getId func(*T) ID, id ID) bool
func ListMap ¶
func ListMap[ID comparable, T Identifiable[ID]](list []*T) map[ID]*T
func ListMerge ¶
func ListMerge[T comparable](list []T, list2 []T, getClone func(T) T, duplicateSkip bool) []T
func MapAdd ¶
func MapAdd[ID comparable, T Identifiable[ID]](m map[ID]*T, items ...*T) map[ID]*T
func MapList ¶
func MapList[ID comparable, T any](m map[ID]*T, skipNil bool) []*T
func MapPick ¶
func MapPick[ID comparable, T Identifiable[ID]](m map[ID]*T, idList IDLister[ID]) []*T
func MapWithIDFunc ¶
func MapWithIDFunc[ID comparable, T any](list []*T, idFunc func(*T) ID, checkNil bool) map[ID]*T
func Merge ¶
func Merge[ID comparable, T Identifiable[ID]](m map[ID]*T, m2 map[ID]*T) map[ID]*T
func OrError ¶
func OrError[T comparable](t T, err error) (r T, _ error)
func Pick ¶
func Pick[ID comparable, T Identifiable[ID]](list []*T, idList IDLister[ID]) []*T
func Properties ¶
func Properties[ID comparable, T any](list []*T, getProperty func(*T) ID) []ID
func Remove ¶
func Remove[ID comparable, T Identifiable[ID]](list []*T, idsToRemove ...ID) []*T
func RemoveById ¶
func RemoveById[ID comparable, T any](list []*T, getId func(*T) ID, id ID) []*T
func RemoveByIds ¶
func RemoveByIds[ID comparable, T any](list []*T, getId func(*T) ID, ids ...ID) []*T
func SortedEntries ¶
func SortedEntries[K constraints.Ordered, V any](m map[K]V) []lo.Entry[K, V]
func Subset
deprecated
func Subset[T comparable](collection, subCollection []T) bool
Subset returns true if all the subCollection items are included in the collection
Deprecated: use lo.Every instead.
func ToGenericList ¶
func ToGenericListValue ¶
func ToGenericListValue[S any, T any](list []S, converter ConverterValue[S, T]) []*T
func ToPtrIfNotEmpty ¶
func ToPtrIfNotEmpty[T comparable](t T) *T
func TryFilterMap ¶
TryFilterMap is similar to TryMap, but if the iteratee returns nil, that element will be omitted from the new slice.
Types ¶
type Cache ¶
type Cache[T any] struct { // contains filtered or unexported fields }
Cache holds data can be accessed synchronously. The data will be automatically updated when it expires.
type ConverterValue ¶
type DiffResult ¶
type DiffResult[T any] struct { Added []T Updated []DiffUpdate[T] NotUpdated []DiffUpdate[T] Deleted []T }
func Diff ¶
func Diff[T any](prev, next []T, keyEqual, isUpdated func(T, T) bool) (r DiffResult[T])
func (DiffResult[T]) NotUpdatedNext ¶
func (d DiffResult[T]) NotUpdatedNext() []T
func (DiffResult[T]) NotUpdatedPrev ¶
func (d DiffResult[T]) NotUpdatedPrev() []T
func (DiffResult[T]) UpdatedNext ¶
func (d DiffResult[T]) UpdatedNext() []T
func (DiffResult[T]) UpdatedPrev ¶
func (d DiffResult[T]) UpdatedPrev() []T
type DiffUpdate ¶
type DiffUpdate[T any] struct { Prev T Next T }
type IDLister ¶
type IDLister[ID comparable] interface { LayerCount() int Layers() []ID }
type Identifiable ¶
type Identifiable[ID comparable] interface { ID() ID }
type List ¶
type List[T comparable] []T
type LockMap ¶
type LockMap[T comparable] struct { // contains filtered or unexported fields }
type SyncMap ¶
type SyncMap[K comparable, V any] struct { // contains filtered or unexported fields }
func NewSyncMap ¶
func NewSyncMap[K comparable, V any]() *SyncMap[K, V]
func SyncMapFrom ¶
func SyncMapFrom[K comparable, V any](entries map[K]V) *SyncMap[K, V]