Documentation
¶
Overview ¶
Package base defines the core collection types and their methods. These types are re-exported via type aliases in the slice and kv packages.
Index ¶
- func FindAs[R, T any](ts []T) option.Option[R]
- func ToSet[T comparable](ts []T) map[T]bool
- type Entries
- func (e Entries[K, V]) Keys() Mapper[K]
- func (e Entries[K, V]) ToAny(fn func(K, V) any) Mapper[any]
- func (e Entries[K, V]) ToBool(fn func(K, V) bool) Mapper[bool]
- func (e Entries[K, V]) ToByte(fn func(K, V) byte) Mapper[byte]
- func (e Entries[K, V]) ToError(fn func(K, V) error) Mapper[error]
- func (e Entries[K, V]) ToFloat32(fn func(K, V) float32) Mapper[float32]
- func (e Entries[K, V]) ToFloat64(fn func(K, V) float64) Float64
- func (e Entries[K, V]) ToInt(fn func(K, V) int) Int
- func (e Entries[K, V]) ToInt32(fn func(K, V) int32) Mapper[int32]
- func (e Entries[K, V]) ToInt64(fn func(K, V) int64) Mapper[int64]
- func (e Entries[K, V]) ToRune(fn func(K, V) rune) Mapper[rune]
- func (e Entries[K, V]) ToString(fn func(K, V) string) String
- func (e Entries[K, V]) Values() Mapper[V]
- type EntryMapper
- type Float64
- type Int
- type Mapper
- func (ts Mapper[T]) Any(fn func(T) bool) bool
- func (ts Mapper[T]) Clone() Mapper[T]
- func (ts Mapper[T]) Convert(fn func(T) T) Mapper[T]
- func (ts Mapper[T]) Each(fn func(T))
- func (ts Mapper[T]) Every(fn func(T) bool) bool
- func (ts Mapper[T]) Find(fn func(T) bool) option.Option[T]
- func (ts Mapper[T]) First() option.Option[T]
- func (ts Mapper[T]) FlatMap(fn func(T) []T) Mapper[T]
- func (ts Mapper[T]) IndexWhere(fn func(T) bool) option.Option[int]
- func (ts Mapper[T]) KeepIf(fn func(T) bool) Mapper[T]
- func (ts Mapper[T]) Len() int
- func (ts Mapper[T]) None(fn func(T) bool) bool
- func (m Mapper[T]) ParallelEach(workers int, fn func(T))
- func (m Mapper[T]) ParallelKeepIf(workers int, fn func(T) bool) Mapper[T]
- func (ts Mapper[T]) RemoveIf(fn func(T) bool) Mapper[T]
- func (ts Mapper[T]) Reverse() Mapper[T]
- func (ts Mapper[T]) Single() either.Either[int, T]
- func (ts Mapper[T]) Sort(cmp func(T, T) int) Mapper[T]
- func (ts Mapper[T]) Take(n int) Mapper[T]
- func (ts Mapper[T]) TakeLast(n int) Mapper[T]
- func (ts Mapper[T]) ToAny(fn func(T) any) Mapper[any]
- func (ts Mapper[T]) ToBool(fn func(T) bool) Mapper[bool]
- func (ts Mapper[T]) ToByte(fn func(T) byte) Mapper[byte]
- func (ts Mapper[T]) ToError(fn func(T) error) Mapper[error]
- func (ts Mapper[T]) ToFloat32(fn func(T) float32) Mapper[float32]
- func (ts Mapper[T]) ToFloat64(fn func(T) float64) Float64
- func (ts Mapper[T]) ToInt(fn func(T) int) Int
- func (ts Mapper[T]) ToInt32(fn func(T) int32) Mapper[int32]
- func (ts Mapper[T]) ToInt64(fn func(T) int64) Mapper[int64]
- func (ts Mapper[T]) ToRune(fn func(T) rune) Mapper[rune]
- func (ts Mapper[T]) ToString(fn func(T) string) String
- type MapperTo
- func (ts MapperTo[R, T]) Clone() MapperTo[R, T]
- func (ts MapperTo[R, T]) Convert(fn func(T) T) MapperTo[R, T]
- func (ts MapperTo[R, T]) Each(fn func(T))
- func (ts MapperTo[R, T]) First() option.Option[T]
- func (ts MapperTo[R, T]) FlatMap(fn func(T) []R) Mapper[R]
- func (ts MapperTo[R, T]) KeepIf(fn func(T) bool) MapperTo[R, T]
- func (ts MapperTo[R, T]) Len() int
- func (ts MapperTo[R, T]) Map(fn func(T) R) Mapper[R]
- func (ts MapperTo[R, T]) ParallelEach(workers int, fn func(T))
- func (ts MapperTo[R, T]) ParallelKeepIf(workers int, fn func(T) bool) MapperTo[R, T]
- func (ts MapperTo[R, T]) ParallelMap(workers int, fn func(T) R) Mapper[R]
- func (ts MapperTo[R, T]) RemoveIf(fn func(T) bool) MapperTo[R, T]
- func (ts MapperTo[R, T]) Reverse() MapperTo[R, T]
- func (ts MapperTo[R, T]) Single() either.Either[int, T]
- func (ts MapperTo[R, T]) Sort(cmp func(T, T) int) MapperTo[R, T]
- func (ts MapperTo[R, T]) Take(n int) MapperTo[R, T]
- func (ts MapperTo[R, T]) TakeLast(n int) MapperTo[R, T]
- func (ts MapperTo[R, T]) ToAny(fn func(T) any) MapperTo[R, any]
- func (ts MapperTo[R, T]) ToBool(fn func(T) bool) MapperTo[R, bool]
- func (ts MapperTo[R, T]) ToByte(fn func(T) byte) MapperTo[R, byte]
- func (ts MapperTo[R, T]) ToError(fn func(T) error) MapperTo[R, error]
- func (ts MapperTo[R, T]) ToFloat32(fn func(T) float32) MapperTo[R, float32]
- func (ts MapperTo[R, T]) ToFloat64(fn func(T) float64) MapperTo[R, float64]
- func (ts MapperTo[R, T]) ToInt(fn func(T) int) MapperTo[R, int]
- func (ts MapperTo[R, T]) ToInt32(fn func(T) int32) MapperTo[R, int32]
- func (ts MapperTo[R, T]) ToInt64(fn func(T) int64) MapperTo[R, int64]
- func (ts MapperTo[R, T]) ToRune(fn func(T) rune) MapperTo[R, rune]
- func (ts MapperTo[R, T]) ToString(fn func(T) string) MapperTo[R, string]
- type String
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindAs ¶
FindAs returns the first element that type-asserts to R, or not-ok if none match. Useful for finding a specific concrete type in a slice of interfaces.
func ToSet ¶
func ToSet[T comparable](ts []T) map[T]bool
ToSet returns a map with each element as a key set to true. Requires comparable elements.
Types ¶
type Entries ¶
type Entries[K comparable, V any] map[K]V
Entries is a defined type over map[K]V. Indexing, ranging, and len all work as with a plain map. The zero value is a nil map — safe for reads (len, range) but panics on write. From does not copy; the Entries and the original map share the same backing data.
func (Entries[K, V]) Keys ¶
Keys extracts the keys as a Mapper for further transformation. Order is not guaranteed (map iteration order).
func (Entries[K, V]) ToFloat32 ¶
ToFloat32 returns the result of applying fn to each key-value pair.
func (Entries[K, V]) ToFloat64 ¶
ToFloat64 returns the result of applying fn to each key-value pair.
type EntryMapper ¶
type EntryMapper[T any, K comparable, V any] struct { // contains filtered or unexported fields }
EntryMapper wraps a map for cross-type transformation. T is first so K and V are inferred from the map argument.
func NewEntryMapper ¶
func NewEntryMapper[T any, K comparable, V any](m map[K]V) EntryMapper[T, K, V]
NewEntryMapper creates an EntryMapper for transformation to type T.
func (EntryMapper[T, K, V]) Map ¶
func (mt EntryMapper[T, K, V]) Map(fn func(K, V) T) Mapper[T]
Map transforms each key-value pair using fn and returns the results as a Mapper for further transformation. Order is not guaranteed (map iteration order).
type Float64 ¶
type Float64 []float64
type Int ¶
type Int []int
type Mapper ¶
type Mapper[T any] []T
Mapper is a fluent slice usable anywhere a regular slice is, but provides additional fluent fp methods. Its underlying type is []T.
func ParallelMap ¶
ParallelMap returns the result of applying fn to each member of m, using the specified number of worker goroutines. Order is preserved. The fn must be safe for concurrent use.
func (Mapper[T]) Every ¶
Every returns true if fn returns true for every element. Returns true for an empty slice (vacuous truth).
func (Mapper[T]) Find ¶
Find returns the first element matching the predicate, or not-ok if none match.
func (Mapper[T]) FlatMap ¶
FlatMap applies fn to each element, concatenating the resulting slices in iteration order. Nil slices returned by fn are treated as empty. The result is always non-nil.
func (Mapper[T]) IndexWhere ¶
IndexWhere returns the index of the first element matching the predicate, or not-ok if none match.
func (Mapper[T]) KeepIf ¶
KeepIf returns a new slice containing the members of ts for which fn returns true. It is the complement of RemoveIf.
func (Mapper[T]) None ¶
None returns true if fn returns false for every element. Returns true for an empty slice (no elements match).
func (Mapper[T]) ParallelEach ¶
ParallelEach applies fn to each member of m, using the specified number of worker goroutines. The fn must be safe for concurrent use.
func (Mapper[T]) ParallelKeepIf ¶
ParallelKeepIf returns a new slice containing members for which fn returns true, using the specified number of worker goroutines. Order is preserved.
func (Mapper[T]) RemoveIf ¶
RemoveIf returns a new slice containing members for which fn returns false. It is the complement of KeepIf.
func (Mapper[T]) Single ¶
Single returns Right(element) if exactly one element exists, or Left(count) if zero or more than one.
func (Mapper[T]) Sort ¶
Sort returns a sorted copy using cmp (negative = a < b, zero = equal, positive = a > b). Build comparators from key extractors using Asc or Desc.
type MapperTo ¶
type MapperTo[R, T any] []T
MapperTo is a fluent slice for filter→map chains where the cross-type map comes last. Prefer slice.Map(ts, fn) for most cross-type mapping — it infers all types and returns Mapper[R] for further chaining. Use MapTo[R] only when you need to filter or transform before the cross-type map: slice.MapTo[R](ts).KeepIf(pred).Map(fn).
func (MapperTo[R, T]) Clone ¶
Clone returns a shallow copy of the slice with independent backing array.
func (MapperTo[R, T]) Each ¶
func (ts MapperTo[R, T]) Each(fn func(T))
Each applies fn to each member of ts.
func (MapperTo[R, T]) FlatMap ¶
FlatMap applies fn to each element, concatenating the resulting slices in iteration order. Nil slices returned by fn are treated as empty. The result is always non-nil.
func (MapperTo[R, T]) KeepIf ¶
KeepIf returns a new slice containing the members of ts for which fn returns true. It is the complement of RemoveIf.
func (MapperTo[R, T]) ParallelEach ¶
ParallelEach applies fn to each member of ts, using the specified number of worker goroutines. The fn must be safe for concurrent use.
func (MapperTo[R, T]) ParallelKeepIf ¶
ParallelKeepIf returns a new slice containing members for which fn returns true, using the specified number of worker goroutines. Order is preserved.
func (MapperTo[R, T]) ParallelMap ¶
ParallelMap returns the result of applying fn to each member of ts, using the specified number of worker goroutines. Order is preserved. The fn must be safe for concurrent use.
func (MapperTo[R, T]) RemoveIf ¶
RemoveIf returns a new slice containing members for which fn returns false. It is the complement of KeepIf.
func (MapperTo[R, T]) Single ¶
Single returns Right(element) if exactly one element exists, or Left(count) if zero or more than one.
func (MapperTo[R, T]) Sort ¶
Sort returns a sorted copy using cmp (negative = a < b, zero = equal, positive = a > b). Build comparators from key extractors using Asc or Desc.
type String ¶
type String []string
func (String) ContainsAny ¶
ContainsAny returns true if ss contains any element in targets. Returns false if either slice is empty.
func (String) Matches ¶
Matches returns true if ss contains any element in filter. Returns true if filter is empty (no constraint).