sliceof

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: Apache-2.0 Imports: 9 Imported by: 18

README

sliceof

Generic, slice-backed types (sliceof.Any, sliceof.Int, sliceof.Int64, sliceof.Float, sliceof.String, sliceof.Object[T], and the MapOfAny/MapOfString variants) that add typed accessors, grouping, and schema integration on top of a plain Go slice. The slice analogue of mapof; part of rosetta.

What matters here

  • Shuffle uses math/rand, not crypto/rand — intentionally. Ordering randomization is not security-sensitive, so the cheaper PRNG is correct here. Do not "upgrade" it to crypto/rand.
  • These types implement the schema array interfaces (Length, GetIndex, SetIndex, GetPointer, SetValue). That is the seam the schema engine walks for array paths; index access there is bounds-checked by schema.Index, so out-of-range paths fail safely rather than panicking.
  • sliceof.Object[T] is generic over the element type, while the scalar types (Any, Int, …) are concrete named slices. Reach for the concrete types when the element type is fixed; use Object[T] only when you genuinely need the type parameter.
  • Reads are bounds-safe; SetIndex grows the slice to fit. GetIndex past the end returns the zero value with ok=false (via slice.AtOK); SetIndex at an out-of-range index extends the slice (growSlice) rather than failing, so setting index 100 on an empty slice yields a length-101 slice with zero-value gaps. Know this before using SetIndex with caller-supplied indices.

Documentation

Overview

Package sliceof provides named slice types that carry helper methods: Any, String, Int, Float, MapOfAny, MapOfString, and the generic Object[T].

Each is a plain []T under its methods, so it ranges, indexes, and serializes like the slice it wraps. What it adds is the Getter and Setter implementations that let the schema package address elements by path, along with the GroupBy helpers that report where a sorted slice changes value in a named field, for rendering group headers.

Together with mapof, these are the carrier types a JSON-Schema-shaped document is read into when there is no Go struct to bind to. For free functions over ordinary slices, see the slice package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Any

type Any []any

Any is a slice of arbitrary values with typed, coercing accessors and schema-traversal support.

func NewAny added in v0.11.0

func NewAny(values ...any) Any

NewAny returns an Any slice containing the provided values (or an empty slice if none are given).

func (*Any) Append added in v0.12.0

func (x *Any) Append(values ...any)

Append adds one or more elements to the end of the slice

func (Any) At added in v0.21.5

func (x Any) At(index int) any

At returns a bound-safe element from the slice. If the index is out of bounds, then `At` returns the zero value for the slice type

func (Any) Contains added in v0.21.4

func (x Any) Contains(value any) bool

Contains returns TRUE if the slice contains the specified value

func (Any) ContainsAll added in v0.21.4

func (x Any) ContainsAll(values ...any) bool

ContainsAll returns TRUE if the slice contains all of the specified values

func (Any) ContainsAny added in v0.21.4

func (x Any) ContainsAny(values ...any) bool

ContainsAny returns TRUE if the slice contains any of the specified values

func (Any) ContainsInterface added in v0.25.9

func (x Any) ContainsInterface(value any) bool

ContainsInterface returns TRUE if the provided generic value is contained in the slice.

func (Any) Equal added in v0.21.4

func (x Any) Equal(value []any) bool

Equal returns TRUE if the slice contains exactly the same elements as the specified value

func (Any) Filter added in v0.25.27

func (x Any) Filter(fn func(any) bool) Any

Filter returns all elements in the slice that satisfies the provided function.

func (Any) Find added in v0.23.0

func (x Any) Find(fn func(any) bool) (any, bool)

Find returns the first element in the slice that satisfies the provided function.

func (Any) First added in v0.10.0

func (x Any) First() any

First returns the first element in the slice, or nil if the slice is empty

func (Any) FirstN added in v0.21.4

func (x Any) FirstN(n int) Any

FirstN returns the first "n" elements in the slice, or all elements if "n" is greater than the length of the slice. A negative "n" returns an empty slice.

func (Any) GetAny

func (x Any) GetAny(key string) any

GetAny returns the value for the key, or nil if absent. The key is a numeric index or "last"/"next".

func (Any) GetAnyOK added in v0.10.0

func (x Any) GetAnyOK(key string) (any, bool)

GetAnyOK returns the value for the key and TRUE if present. The key is a numeric index or "last"/"next".

func (Any) GetBool

func (x Any) GetBool(key string) bool

GetBool returns the value for the key coerced to bool, or FALSE if absent or not coercible.

func (Any) GetBoolOK added in v0.11.0

func (x Any) GetBoolOK(key string) (bool, bool)

GetBoolOK returns the value for the key coerced to bool, with TRUE if it was present and coercible.

func (Any) GetFloat

func (x Any) GetFloat(key string) float64

GetFloat returns the value for the key coerced to float64, or 0 if absent or not coercible.

func (Any) GetFloatOK added in v0.10.0

func (x Any) GetFloatOK(key string) (float64, bool)

GetFloatOK returns the value for the key coerced to float64, with TRUE if it was present and coercible.

func (Any) GetIndex added in v0.22.0

func (x Any) GetIndex(index int) (any, bool)

GetIndex returns the value at the index and TRUE, or (nil, false) if out of range.

func (Any) GetInt

func (x Any) GetInt(key string) int

GetInt returns the value for the key coerced to int, or 0 if absent or not coercible.

func (Any) GetInt64

func (x Any) GetInt64(key string) int64

GetInt64 returns the value for the key coerced to int64, or 0 if absent or not coercible.

func (Any) GetInt64OK added in v0.11.0

func (x Any) GetInt64OK(key string) (int64, bool)

GetInt64OK returns the value for the key coerced to int64, with TRUE if it was present and coercible.

func (Any) GetIntOK added in v0.11.0

func (x Any) GetIntOK(key string) (int, bool)

GetIntOK returns the value for the key coerced to int, with TRUE if it was present and coercible.

func (*Any) GetPointer added in v0.14.0

func (x *Any) GetPointer(key string) (any, bool)

GetPointer returns a pointer to the element at the key index, growing the slice as needed (implements schema PointerGetter).

func (Any) GetString

func (x Any) GetString(key string) string

GetString returns the value for the key coerced to string, or "" if absent or not coercible.

func (Any) GetStringOK added in v0.11.0

func (x Any) GetStringOK(key string) (string, bool)

GetStringOK returns the value for the key coerced to string, with TRUE if it was present and coercible.

func (Any) GroupBy added in v0.25.20

func (x Any) GroupBy(field string) AnyGrouper

GroupBy returns a grouper that detects boundaries in this slice using the named field.

func (Any) IsEmpty added in v0.10.0

func (x Any) IsEmpty() bool

IsEmpty returns TRUE if the slice contains no elements

func (Any) IsLength added in v0.10.0

func (x Any) IsLength(length int) bool

IsLength returns TRUE if the slice contains exactly "length" elements

func (Any) IsZero added in v0.25.22

func (x Any) IsZero() bool

IsZero returns TRUE if the slice contains no elements. This is an alias for IsEmpty, and implements the `Zeroer` interface used by many packages (including go/json)

func (Any) Keys added in v0.22.0

func (x Any) Keys() []string

Keys returns a slice of strings representing the indexes of this slice

func (Any) Last added in v0.10.0

func (x Any) Last() any

Last returns the last element in the slice, or nil if the slice is empty

func (Any) Length added in v0.10.0

func (x Any) Length() int

Length returns the number of elements in the slice

func (Any) NotEmpty added in v0.16.3

func (x Any) NotEmpty() bool

NotEmpty returns TRUE if the slice contains at least one element

func (Any) Range added in v0.25.11

func (x Any) Range() iter.Seq2[int, any]

Range returns an iterator that yields each value in this slice.

func (*Any) Remove added in v0.10.0

func (x *Any) Remove(key string) bool

Remove removes the element with the specified key

func (*Any) RemoveAt added in v0.25.12

func (x *Any) RemoveAt(index int) bool

RemoveAt removes the element at the specified index

func (Any) Reverse added in v0.10.0

func (x Any) Reverse() Any

Reverse returns a new slice with the elements in reverse order

func (*Any) SetAny

func (x *Any) SetAny(key string, value any) bool

SetAny stores the value at the key index (growing the slice to fit), returning FALSE for a non-index key.

func (*Any) SetBool

func (x *Any) SetBool(key string, value bool) bool

SetBool stores a bool value at the key index.

func (*Any) SetFloat

func (x *Any) SetFloat(key string, value float64) bool

SetFloat sets a property with a float64 value

func (*Any) SetIndex added in v0.24.0

func (x *Any) SetIndex(index int, value any) bool

SetIndex stores the value at the index, growing the slice to fit if necessary.

func (*Any) SetInt

func (x *Any) SetInt(key string, value int) bool

SetInt sets a property with an int value

func (*Any) SetInt64

func (x *Any) SetInt64(key string, value int64) bool

SetInt64 sets a property with an int64 value

func (*Any) SetString

func (x *Any) SetString(key string, value string) bool

SetString sets a property with an string value

func (*Any) SetValue added in v0.10.0

func (x *Any) SetValue(value any) error

SetValue sets the entire value of this slice to the provided value

func (Any) Shuffle added in v0.21.4

func (x Any) Shuffle() Any

Shuffle randomizes the order of the elements in the slice

type AnyGrouper added in v0.25.20

type AnyGrouper struct {
	// contains filtered or unexported fields
}

AnyGrouper reports group boundaries within an Any slice, grouped by a named field.

func (AnyGrouper) IsFooter added in v0.25.20

func (grouper AnyGrouper) IsFooter(index int) bool

IsFooter returns TRUE if the element at index ends a group.

func (AnyGrouper) IsHeader added in v0.25.20

func (grouper AnyGrouper) IsHeader(index int) bool

IsHeader returns TRUE if the element at index begins a new group.

type Float

type Float []float64

Float is a slice of float64 values with typed accessors and schema-traversal support.

func NewFloat added in v0.11.0

func NewFloat(values ...float64) Float

NewFloat returns a Float slice containing the provided values (or an empty slice if none are given).

func (*Float) Append added in v0.12.0

func (x *Float) Append(values ...float64)

Append adds one or more elements to the end of the slice

func (Float) At added in v0.21.5

func (x Float) At(index int) float64

At returns a bound-safe element from the slice. If the index is out of bounds, then `At` returns the zero value for the slice type

func (Float) Contains added in v0.11.2

func (x Float) Contains(value float64) bool

Contains returns TRUE if the slice contains the specified value

func (Float) ContainsAll added in v0.14.0

func (x Float) ContainsAll(values ...float64) bool

ContainsAll returns TRUE if the slice contains all of the specified values

func (Float) ContainsAny added in v0.14.0

func (x Float) ContainsAny(values ...float64) bool

ContainsAny returns TRUE if the slice contains any of the specified values

func (Float) ContainsFloaterface added in v0.25.21

func (x Float) ContainsFloaterface(value any) bool

ContainsFloaterface returns TRUE if the provided generic value is contained in the slice.

func (Float) Equal added in v0.11.2

func (x Float) Equal(value []float64) bool

Equal returns TRUE if the slice contains exactly the same elements as the "value" slice

func (Float) Filter added in v0.25.27

func (x Float) Filter(fn func(float64) bool) Float

Filter returns all elements in the slice that satisfies the provided function.

func (Float) Find added in v0.25.21

func (x Float) Find(fn func(float64) bool) (float64, bool)

Find returns the first element in the slice that satisfies the provided function.

func (Float) First added in v0.10.0

func (x Float) First() float64

First returns the first element in the slice, or nil if the slice is empty

func (Float) FirstN added in v0.21.4

func (x Float) FirstN(n int) Float

FirstN returns the first "n" elements in the slice, or all elements if "n" is greater than the length of the slice. A negative "n" returns an empty slice.

func (Float) GetAny added in v0.25.21

func (x Float) GetAny(key string) any

GetAny returns the rquested property as an any type

func (Float) GetAnyOK added in v0.25.21

func (x Float) GetAnyOK(key string) (any, bool)

GetAnyOK returns the requested property as an any type and a boolean TRUE/FALSE value indicating whether the value was found

func (Float) GetFloat

func (x Float) GetFloat(key string) float64

GetFloat returns the requested property as a float64 type

func (Float) GetFloatOK added in v0.10.0

func (x Float) GetFloatOK(key string) (float64, bool)

GetFloatOK returns the requested property as a float64 type and a boolean TRUE/FALSE value indicating whether the value was found

func (Float) GetIndex added in v0.26.0

func (x Float) GetIndex(index int) (any, bool)

GetIndex returns the value at the specified index, and a boolean indicating success

func (Float) IsEmpty added in v0.10.0

func (x Float) IsEmpty() bool

IsEmpty returns TRUE if the slice contains no elements

func (Float) IsLength added in v0.10.0

func (x Float) IsLength(length int) bool

IsLength returns TRUE if the slice contains exactly "length" elements

func (Float) IsZero added in v0.25.22

func (x Float) IsZero() bool

IsZero returns TRUE if the slice contains no elements. This is an alias for IsEmpty, and implements the `Zeroer` interface used by many packages (including go/json)

func (Float) Keys added in v0.25.21

func (x Float) Keys() []string

Keys returns a slice of float64s representing the indexes of this slice

func (Float) Last added in v0.10.0

func (x Float) Last() float64

Last returns the last element in the slice, or nil if the slice is empty

func (Float) Length added in v0.10.0

func (x Float) Length() int

Length returns the number of elements in the slice

func (Float) NotContains added in v0.25.21

func (x Float) NotContains(value float64) bool

NotContains returns TRUE if the slice does not contain the provided value.

func (Float) NotEmpty added in v0.16.3

func (x Float) NotEmpty() bool

NotEmpty returns TRUE if the slice contains at least one element

func (Float) NotEqual added in v0.25.21

func (x Float) NotEqual(value []float64) bool

NotEqual returns TRUE if the slice DOES NOT contain exactly the same elements as the "value" slice

func (Float) Range added in v0.25.21

func (x Float) Range() iter.Seq2[int, float64]

Range returns an iterator that yields each value in this slice.

func (*Float) Remove added in v0.10.0

func (s *Float) Remove(key string) bool

Remove deletes the element at the specified key

func (*Float) RemoveAt added in v0.25.21

func (x *Float) RemoveAt(index int) bool

RemoveAt deletes the element at the specified index

func (Float) Reverse added in v0.10.0

func (x Float) Reverse() Float

Reverse modifies the slice with the elements in reverse order

func (*Float) SetFloat

func (s *Float) SetFloat(key string, value float64) bool

SetFloat sets the value at the specified key, growing the slice if necessary

func (*Float) SetIndex added in v0.25.21

func (s *Float) SetIndex(index int, value any) bool

SetIndex sets the value at the specified index, growing the slice if necessary

func (*Float) SetValue added in v0.10.0

func (s *Float) SetValue(value any) error

SetValue sets the value at the specified index, growing the slice if necessary

func (Float) Shuffle added in v0.21.4

func (x Float) Shuffle() Float

Shuffle randomizes the order of the elements in the slice

type Int

type Int []int

Int is a slice of int values with typed accessors and schema-traversal support.

func NewInt added in v0.11.0

func NewInt(values ...int) Int

NewInt returns an Int slice containing the provided values (or an empty slice if none are given).

func (*Int) Append added in v0.12.0

func (x *Int) Append(values ...int)

Append adds one or more elements to the end of the slice

func (Int) At added in v0.21.5

func (x Int) At(index int) int

At returns a bound-safe element from the slice. If the index is out of bounds, then `At` returns the zero value for the slice type

func (Int) Contains added in v0.11.2

func (x Int) Contains(value int) bool

Contains returns TRUE if the slice contains the specified value

func (Int) ContainsAll added in v0.14.0

func (x Int) ContainsAll(values ...int) bool

ContainsAll returns TRUE if the slice contains all of the specified values

func (Int) ContainsAny added in v0.14.0

func (x Int) ContainsAny(values ...int) bool

ContainsAny returns TRUE if the slice contains any of the specified values

func (Int) ContainsInterface added in v0.25.9

func (x Int) ContainsInterface(value any) bool

ContainsInterface returns TRUE if the provided generic value is contained in the slice.

func (Int) Equal added in v0.11.2

func (x Int) Equal(value []int) bool

Equal returns TRUE if the slice contains exactly the same elements as the "value" slice

func (Int) Filter added in v0.25.27

func (x Int) Filter(fn func(int) bool) Int

Filter returns all elements in the slice that satisfies the provided function.

func (Int) Find added in v0.25.8

func (x Int) Find(fn func(int) bool) (int, bool)

Find returns the first element in the slice that satisfies the provided function.

func (Int) First added in v0.10.0

func (x Int) First() int

First returns the first element in the slice, or nil if the slice is empty

func (Int) FirstN added in v0.21.4

func (x Int) FirstN(n int) Int

FirstN returns the first "n" elements in the slice, or all elements if "n" is greater than the length of the slice. A negative "n" returns an empty slice.

func (Int) GetAny added in v0.25.8

func (x Int) GetAny(key string) any

GetAny returns the value for the key index, or nil if absent.

func (Int) GetAnyOK added in v0.25.8

func (x Int) GetAnyOK(key string) (any, bool)

GetAnyOK returns the value for the key index and TRUE if present.

func (Int) GetIndex added in v0.26.0

func (x Int) GetIndex(index int) (any, bool)

GetIndex returns the value at the specified index, and a boolean indicating success

func (Int) GetInt

func (x Int) GetInt(key string) int

GetInt returns the value for the key index coerced to int, or 0 if absent.

func (Int) GetIntOK added in v0.11.0

func (x Int) GetIntOK(key string) (int, bool)

GetIntOK returns the value for the key index coerced to int, with TRUE if present.

func (Int) IsEmpty added in v0.10.0

func (x Int) IsEmpty() bool

IsEmpty returns TRUE if the slice contains no elements

func (Int) IsLength added in v0.10.0

func (x Int) IsLength(length int) bool

IsLength returns TRUE if the slice contains exactly "length" elements

func (Int) IsZero added in v0.25.22

func (x Int) IsZero() bool

IsZero returns TRUE if the slice contains no elements. This is an alias for IsEmpty, and implements the `Zeroer` interface used by many packages (including go/json)

func (Int) Keys added in v0.25.8

func (x Int) Keys() []string

Keys returns a slice of ints representing the indexes of this slice

func (Int) Last added in v0.10.0

func (x Int) Last() int

Last returns the last element in the slice, or nil if the slice is empty

func (Int) Length added in v0.10.0

func (x Int) Length() int

Length returns the number of elements in the slice

func (Int) NotContains added in v0.25.8

func (x Int) NotContains(value int) bool

NotContains returns TRUE if the slice does not contain the provided value.

func (Int) NotEmpty added in v0.16.3

func (x Int) NotEmpty() bool

NotEmpty returns TRUE if the slice contains at least one element

func (Int) NotEqual added in v0.25.8

func (x Int) NotEqual(value []int) bool

NotEqual returns TRUE if the slice DOES NOT contain exactly the same elements as the "value" slice

func (Int) Range added in v0.25.11

func (x Int) Range() iter.Seq2[int, int]

Range returns an iterator that yields each value in this slice.

func (*Int) Remove added in v0.10.0

func (s *Int) Remove(key string) bool

Remove deletes the element identified by the key index.

func (*Int) RemoveAt added in v0.25.12

func (x *Int) RemoveAt(index int) bool

RemoveAt deletes the element at the given index.

func (Int) Reverse added in v0.10.0

func (x Int) Reverse() Int

Reverse modifies the slice with the elements in reverse order

func (*Int) SetIndex added in v0.25.8

func (s *Int) SetIndex(index int, value any) bool

SetIndex stores the value at the index, growing the slice to fit if necessary.

func (*Int) SetInt

func (s *Int) SetInt(key string, value int) bool

SetInt stores an int value at the key index.

func (*Int) SetValue added in v0.10.0

func (s *Int) SetValue(value any) error

SetValue replaces the entire slice with the provided value, if it can be converted.

func (Int) Shuffle added in v0.21.4

func (x Int) Shuffle() Int

Shuffle randomizes the order of the elements in the slice

type MapOfAny added in v0.25.24

type MapOfAny []mapof.Any

MapOfAny is a slice of mapof.Any objects with typed accessors and schema-traversal support.

func NewMapOfAny added in v0.25.24

func NewMapOfAny(values ...mapof.Any) MapOfAny

NewMapOfAny returns a MapOfAny slice containing the provided values (or an empty slice if none are given).

func (*MapOfAny) Append added in v0.25.24

func (x *MapOfAny) Append(values ...mapof.Any)

Append adds one or more elements to the end of the slice

func (MapOfAny) At added in v0.25.24

func (x MapOfAny) At(index int) mapof.Any

At returns a bound-safe element from the slice. If the index is out of bounds, then `At` returns the zero value for the slice type

func (MapOfAny) AtOK added in v0.25.24

func (x MapOfAny) AtOK(index int) (mapof.Any, bool)

AtOK returns the element at the index and TRUE, or the zero value and FALSE if out of range.

func (MapOfAny) Contains added in v0.25.24

func (x MapOfAny) Contains(match func(mapof.Any) bool) bool

Contains returns TRUE if the "match" function returns TRUE for any element in the slice

func (MapOfAny) Filter added in v0.25.27

func (x MapOfAny) Filter(fn func(mapof.Any) bool) MapOfAny

Filter returns all elements in the slice that satisfies the provided function.

func (MapOfAny) Find added in v0.25.24

func (x MapOfAny) Find(fn func(mapof.Any) bool) (mapof.Any, bool)

Find returns the first element in the slice that satisfies the provided function.

func (MapOfAny) First added in v0.25.24

func (x MapOfAny) First() mapof.Any

First returns the first element in the slice, or nil if the slice is empty

func (MapOfAny) FirstN added in v0.25.24

func (x MapOfAny) FirstN(n int) MapOfAny

FirstN returns the first "n" elements in the slice, or all elements if "n" is greater than the length of the slice. A negative "n" returns an empty slice.

func (MapOfAny) GetAny added in v0.25.24

func (x MapOfAny) GetAny(key string) any

GetAny returns the value for the key index, or nil if absent.

func (MapOfAny) GetAnyOK added in v0.25.24

func (x MapOfAny) GetAnyOK(key string) (any, bool)

GetAnyOK returns the value for the key index and TRUE if present.

func (MapOfAny) GetIndex added in v0.26.0

func (x MapOfAny) GetIndex(index int) (any, bool)

GetIndex returns the value at the specified index, and a boolean indicating success

func (*MapOfAny) GetPointer added in v0.25.24

func (x *MapOfAny) GetPointer(name string) (any, bool)

GetPointer returns a pointer to the element at the key index, growing the slice as needed (implements schema PointerGetter).

func (MapOfAny) GroupBy added in v0.25.24

func (x MapOfAny) GroupBy(field string) MapOfAnyGrouper

GroupBy returns a grouper that detects boundaries in this slice using the named field.

func (MapOfAny) IsEmpty added in v0.25.24

func (x MapOfAny) IsEmpty() bool

IsEmpty returns TRUE if the slice contains no elements

func (MapOfAny) IsLength added in v0.25.24

func (x MapOfAny) IsLength(length int) bool

IsLength returns TRUE if the slice contains exactly "length" elements

func (MapOfAny) IsZero added in v0.25.24

func (x MapOfAny) IsZero() bool

IsZero returns TRUE if the slice contains no elements. This is an alias for IsEmpty, and implements the `Zeroer` interface used by many packages (including go/json)

func (MapOfAny) Keys added in v0.25.24

func (x MapOfAny) Keys() []string

Keys returns a slice of strings representing the indexes of this slice

func (MapOfAny) Last added in v0.25.24

func (x MapOfAny) Last() mapof.Any

Last returns the last element in the slice, or nil if the slice is empty

func (MapOfAny) Length added in v0.25.24

func (x MapOfAny) Length() int

Length returns the number of elements in the slice

func (MapOfAny) NotEmpty added in v0.25.24

func (x MapOfAny) NotEmpty() bool

NotEmpty returns TRUE if the slice contains at least one element

func (MapOfAny) Range added in v0.25.24

func (x MapOfAny) Range() iter.Seq2[int, mapof.Any]

Range returns an iterator that yields each value in this slice.

func (*MapOfAny) Remove added in v0.25.24

func (x *MapOfAny) Remove(key string) bool

Remove deletes the element identified by the key index.

func (*MapOfAny) RemoveAt added in v0.25.24

func (x *MapOfAny) RemoveAt(index int) bool

RemoveAt deletes the element at the given index.

func (MapOfAny) Reverse added in v0.25.24

func (x MapOfAny) Reverse() MapOfAny

Reverse returns a new slice with the elements in reverse order

func (*MapOfAny) SetIndex added in v0.25.24

func (s *MapOfAny) SetIndex(index int, value any) bool

SetIndex stores the value at the index, growing the slice to fit if necessary.

func (*MapOfAny) SetValue added in v0.25.24

func (s *MapOfAny) SetValue(value any) error

SetValue replaces the entire slice with the provided value, if it can be converted.

func (MapOfAny) Shuffle added in v0.25.24

func (x MapOfAny) Shuffle() MapOfAny

Shuffle randomizes the order of the elements in the slice

type MapOfAnyGrouper added in v0.25.24

type MapOfAnyGrouper struct {
	// contains filtered or unexported fields
}

MapOfAnyGrouper reports group boundaries within a MapOfAny slice, grouped by a named field.

func (MapOfAnyGrouper) IsFooter added in v0.25.24

func (grouper MapOfAnyGrouper) IsFooter(index int) bool

IsFooter returns TRUE if the element at index ends a group.

func (MapOfAnyGrouper) IsHeader added in v0.25.24

func (grouper MapOfAnyGrouper) IsHeader(index int) bool

IsHeader returns TRUE if the element at index begins a new group.

type MapOfString added in v0.25.24

type MapOfString []mapof.String

MapOfString is a slice of mapof.String objects with typed accessors and schema-traversal support.

func NewMapOfString added in v0.25.24

func NewMapOfString(values ...mapof.String) MapOfString

NewMapOfString returns a MapOfString slice containing the provided values (or an empty slice if none are given).

func (*MapOfString) Append added in v0.25.24

func (x *MapOfString) Append(values ...mapof.String)

Append adds one or more elements to the end of the slice

func (MapOfString) At added in v0.25.24

func (x MapOfString) At(index int) mapof.String

At returns a bound-safe element from the slice. If the index is out of bounds, then `At` returns the zero value for the slice type

func (MapOfString) AtOK added in v0.25.24

func (x MapOfString) AtOK(index int) (mapof.String, bool)

AtOK returns the element at the index and TRUE, or the zero value and FALSE if out of range.

func (MapOfString) Contains added in v0.25.24

func (x MapOfString) Contains(match func(mapof.String) bool) bool

Contains returns TRUE if the "match" function returns TRUE for any element in the slice

func (MapOfString) Filter added in v0.25.27

func (x MapOfString) Filter(fn func(mapof.String) bool) MapOfString

Filter returns all elements in the slice that satisfies the provided function.

func (MapOfString) Find added in v0.25.24

func (x MapOfString) Find(fn func(mapof.String) bool) (mapof.String, bool)

Find returns the first element in the slice that satisfies the provided function.

func (MapOfString) First added in v0.25.24

func (x MapOfString) First() mapof.String

First returns the first element in the slice, or nil if the slice is empty

func (MapOfString) FirstN added in v0.25.24

func (x MapOfString) FirstN(n int) MapOfString

FirstN returns the first "n" elements in the slice, or all elements if "n" is greater than the length of the slice. A negative "n" returns an empty slice.

func (MapOfString) GetAny added in v0.25.24

func (x MapOfString) GetAny(key string) any

GetAny returns the value for the key index, or nil if absent.

func (MapOfString) GetAnyOK added in v0.25.24

func (x MapOfString) GetAnyOK(key string) (any, bool)

GetAnyOK returns the value for the key index and TRUE if present.

func (MapOfString) GetIndex added in v0.26.0

func (x MapOfString) GetIndex(index int) (any, bool)

GetIndex returns the value at the specified index, and a boolean indicating success

func (*MapOfString) GetPointer added in v0.25.24

func (x *MapOfString) GetPointer(name string) (any, bool)

GetPointer returns a pointer to the element at the key index, growing the slice as needed (implements schema PointerGetter).

func (MapOfString) GroupBy added in v0.25.24

func (x MapOfString) GroupBy(field string) MapOfStringGrouper

GroupBy returns a grouper that detects boundaries in this slice using the named field.

func (MapOfString) IsEmpty added in v0.25.24

func (x MapOfString) IsEmpty() bool

IsEmpty returns TRUE if the slice contains no elements

func (MapOfString) IsLength added in v0.25.24

func (x MapOfString) IsLength(length int) bool

IsLength returns TRUE if the slice contains exactly "length" elements

func (MapOfString) IsZero added in v0.25.24

func (x MapOfString) IsZero() bool

IsZero returns TRUE if the slice contains no elements. This is an alias for IsEmpty, and implements the `Zeroer` interface used by many packages (including go/json)

func (MapOfString) Keys added in v0.25.24

func (x MapOfString) Keys() []string

Keys returns a slice of strings representing the indexes of this slice

func (MapOfString) Last added in v0.25.24

func (x MapOfString) Last() mapof.String

Last returns the last element in the slice, or nil if the slice is empty

func (MapOfString) Length added in v0.25.24

func (x MapOfString) Length() int

Length returns the number of elements in the slice

func (MapOfString) NotEmpty added in v0.25.24

func (x MapOfString) NotEmpty() bool

NotEmpty returns TRUE if the slice contains at least one element

func (MapOfString) Range added in v0.25.24

func (x MapOfString) Range() iter.Seq2[int, mapof.String]

Range returns an iterator that yields each value in this slice.

func (*MapOfString) Remove added in v0.25.24

func (x *MapOfString) Remove(key string) bool

Remove deletes the element identified by the key index.

func (*MapOfString) RemoveAt added in v0.25.24

func (x *MapOfString) RemoveAt(index int) bool

RemoveAt deletes the element at the given index.

func (MapOfString) Reverse added in v0.25.24

func (x MapOfString) Reverse() MapOfString

Reverse returns a new slice with the elements in reverse order

func (*MapOfString) SetIndex added in v0.25.24

func (s *MapOfString) SetIndex(index int, value any) bool

SetIndex stores the value at the index, growing the slice to fit if necessary.

func (*MapOfString) SetValue added in v0.25.24

func (s *MapOfString) SetValue(value any) error

SetValue replaces the entire slice with the provided value, if it can be converted.

func (MapOfString) Shuffle added in v0.25.24

func (x MapOfString) Shuffle() MapOfString

Shuffle randomizes the order of the elements in the slice

type MapOfStringGrouper added in v0.25.24

type MapOfStringGrouper struct {
	// contains filtered or unexported fields
}

MapOfStringGrouper reports group boundaries within a MapOfString slice, grouped by a named field.

func (MapOfStringGrouper) IsFooter added in v0.25.24

func (grouper MapOfStringGrouper) IsFooter(index int) bool

IsFooter returns TRUE if the element at index ends a group.

func (MapOfStringGrouper) IsHeader added in v0.25.24

func (grouper MapOfStringGrouper) IsHeader(index int) bool

IsHeader returns TRUE if the element at index begins a new group.

type Object added in v0.10.0

type Object[T any] []T

Object is a slice of values of a single type T, with typed accessors and schema-traversal support.

func NewObject added in v0.11.0

func NewObject[T any](values ...T) Object[T]

NewObject returns an Object slice containing the provided values (or an empty slice if none are given).

func (*Object[T]) Append added in v0.12.0

func (x *Object[T]) Append(values ...T)

Append adds one or more elements to the end of the slice

func (Object[T]) At added in v0.21.5

func (x Object[T]) At(index int) T

At returns a bound-safe element from the slice. If the index is out of bounds, then `At` returns the zero value for the slice type

func (Object[T]) AtOK added in v0.22.0

func (x Object[T]) AtOK(index int) (T, bool)

AtOK returns the element at the index and TRUE, or the zero value and FALSE if out of range.

func (Object[T]) Contains added in v0.24.4

func (x Object[T]) Contains(match func(T) bool) bool

Contains returns TRUE if the "match" function returns TRUE for any element in the slice

func (Object[T]) Filter added in v0.25.27

func (x Object[T]) Filter(fn func(T) bool) Object[T]

Filter returns all elements in the slice that satisfies the provided function.

func (Object[T]) Find added in v0.23.0

func (x Object[T]) Find(fn func(T) bool) (T, bool)

Find returns the first element in the slice that satisfies the provided function.

func (Object[T]) First added in v0.10.0

func (x Object[T]) First() T

First returns the first element in the slice, or nil if the slice is empty

func (Object[T]) FirstN added in v0.21.4

func (x Object[T]) FirstN(n int) Object[T]

FirstN returns the first "n" elements in the slice, or all elements if "n" is greater than the length of the slice. A negative "n" returns an empty slice.

func (Object[T]) GetAny added in v0.22.0

func (x Object[T]) GetAny(key string) any

GetAny returns the value for the key index, or nil if absent.

func (Object[T]) GetAnyOK added in v0.22.0

func (x Object[T]) GetAnyOK(key string) (any, bool)

GetAnyOK returns the value for the key index and TRUE if present.

func (Object[T]) GetIndex added in v0.26.0

func (x Object[T]) GetIndex(index int) (any, bool)

GetIndex returns the value at the specified index, and a boolean indicating success

func (*Object[T]) GetPointer added in v0.14.0

func (x *Object[T]) GetPointer(name string) (any, bool)

GetPointer returns a pointer to the element at the key index, growing the slice as needed (implements schema PointerGetter).

func (Object[T]) GroupBy added in v0.25.20

func (x Object[T]) GroupBy(field string) ObjectGrouper[T]

GroupBy returns an Grouper object for this slice

func (Object[T]) IsEmpty added in v0.10.0

func (x Object[T]) IsEmpty() bool

IsEmpty returns TRUE if the slice contains no elements

func (Object[T]) IsLength added in v0.10.0

func (x Object[T]) IsLength(length int) bool

IsLength returns TRUE if the slice contains exactly "length" elements

func (Object[T]) IsZero added in v0.25.22

func (x Object[T]) IsZero() bool

IsZero returns TRUE if the slice contains no elements. This is an alias for IsEmpty, and implements the `Zeroer` interface used by many packages (including go/json)

func (Object[T]) Keys added in v0.22.0

func (x Object[T]) Keys() []string

Keys returns a slice of strings representing the indexes of this slice

func (Object[T]) Last added in v0.10.0

func (x Object[T]) Last() T

Last returns the last element in the slice, or nil if the slice is empty

func (Object[T]) Length added in v0.10.0

func (x Object[T]) Length() int

Length returns the number of elements in the slice

func (Object[T]) NotEmpty added in v0.16.3

func (x Object[T]) NotEmpty() bool

NotEmpty returns TRUE if the slice contains at least one element

func (Object[T]) Range added in v0.25.11

func (x Object[T]) Range() iter.Seq2[int, T]

Range returns an iterator that yields each value in this slice.

func (*Object[T]) Remove added in v0.10.0

func (x *Object[T]) Remove(key string) bool

Remove deletes the element identified by the key index.

func (*Object[T]) RemoveAt added in v0.25.12

func (x *Object[T]) RemoveAt(index int) bool

RemoveAt deletes the element at the given index.

func (Object[T]) Reverse added in v0.10.0

func (x Object[T]) Reverse() Object[T]

Reverse returns a new slice with the elements in reverse order

func (*Object[T]) SetIndex added in v0.24.0

func (s *Object[T]) SetIndex(index int, value any) bool

SetIndex stores the value at the index, growing the slice to fit if necessary.

func (*Object[T]) SetValue added in v0.22.1

func (s *Object[T]) SetValue(value any) error

SetValue replaces the entire slice with the provided value, if it can be converted.

func (Object[T]) Shuffle added in v0.21.4

func (x Object[T]) Shuffle() Object[T]

Shuffle randomizes the order of the elements in the slice

type ObjectGrouper added in v0.25.20

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

ObjectGrouper calculates group headers and footers for a sliceof.Object

func (ObjectGrouper[T]) IsFooter added in v0.25.20

func (grouper ObjectGrouper[T]) IsFooter(index int) bool

IsFooter returns TRUE if the record at the given index is the LAST item in a group

func (ObjectGrouper[T]) IsHeader added in v0.25.20

func (grouper ObjectGrouper[T]) IsHeader(index int) bool

IsHeader returns TRUE if the record at the given index is the FIRST item in a group.

type String

type String []string

String is a slice of string values with typed accessors and schema-traversal support.

func NewString added in v0.11.0

func NewString(values ...string) String

NewString returns a String slice containing the provided values (or an empty slice if none are given).

func (*String) Append added in v0.12.0

func (x *String) Append(values ...string)

Append adds one or more elements to the end of the slice

func (String) At added in v0.21.5

func (x String) At(index int) string

At returns a bound-safe element from the slice. If the index is out of bounds, then `At` returns the zero value for the slice type

func (String) Contains added in v0.11.2

func (x String) Contains(value string) bool

Contains returns TRUE if the slice contains the specified value

func (String) ContainsAll added in v0.14.0

func (x String) ContainsAll(values ...string) bool

ContainsAll returns TRUE if the slice contains all of the specified values

func (String) ContainsAny added in v0.14.0

func (x String) ContainsAny(values ...string) bool

ContainsAny returns TRUE if the slice contains any of the specified values

func (String) ContainsInterface added in v0.25.9

func (x String) ContainsInterface(value any) bool

ContainsInterface returns TRUE if the provided generic value is contained in the slice.

func (String) Equal added in v0.11.2

func (x String) Equal(value []string) bool

Equal returns TRUE if the slice contains exactly the same elements as the "value" slice

func (String) Find added in v0.23.0

func (x String) Find(fn func(string) bool) (string, bool)

Find returns the first element in the slice that satisfies the provided function.

func (String) First added in v0.10.0

func (x String) First() string

First returns the first element in the slice, or nil if the slice is empty

func (String) FirstN added in v0.21.5

func (x String) FirstN(n int) String

FirstN returns the first "n" elements in the slice, or all elements if "n" is greater than the length of the slice. A negative "n" returns an empty slice.

func (String) GetAny added in v0.22.0

func (x String) GetAny(key string) any

GetAny returns the value at the specified key as an "any" type

func (String) GetAnyOK added in v0.22.0

func (x String) GetAnyOK(key string) (any, bool)

GetAnyOK returns the value at the specified key as an "any" type, along with a boolean indicating success

func (String) GetIndex added in v0.26.0

func (x String) GetIndex(index int) (any, bool)

GetIndex returns the value at the specified index, and a boolean indicating success

func (String) GetString

func (x String) GetString(key string) string

GetString returns the string value at the specified key

func (String) GetStringOK added in v0.11.0

func (x String) GetStringOK(key string) (string, bool)

GetStringOK returns the string value at the specified key, along with a boolean indicating success

func (String) IsEmpty added in v0.10.0

func (x String) IsEmpty() bool

IsEmpty returns TRUE if the slice contains no elements

func (String) IsLength added in v0.10.0

func (x String) IsLength(length int) bool

IsLength returns TRUE if the slice contains exactly "length" elements

func (String) IsZero added in v0.25.22

func (x String) IsZero() bool

IsZero returns TRUE if the slice contains no elements. This is an alias for IsEmpty, and implements the `Zeroer` interface used by many packages (including go/json)

func (String) Join added in v0.19.1

func (x String) Join(delimiter string) string

Join concatenates all elements of the slice into a single string, separated by the specified delimiter

func (String) Keys added in v0.22.0

func (x String) Keys() []string

Keys returns a slice of strings representing the indexes of this slice

func (String) Last added in v0.10.0

func (x String) Last() string

Last returns the last element in the slice, or nil if the slice is empty

func (String) Length added in v0.10.0

func (x String) Length() int

Length returns the number of elements in the slice

func (String) NotContains added in v0.25.8

func (x String) NotContains(value string) bool

NotContains returns TRUE if the slice does not contain the provided value.

func (String) NotEmpty added in v0.16.3

func (x String) NotEmpty() bool

NotEmpty returns TRUE if the slice contains at least one element

func (String) NotEqual added in v0.24.8

func (x String) NotEqual(value []string) bool

NotEqual returns TRUE if the slice DOES NOT contain exactly the same elements as the "value" slice

func (String) Range added in v0.25.11

func (x String) Range() iter.Seq2[int, string]

Range returns an iterator that yields each value in this slice.

func (*String) Remove added in v0.10.0

func (x *String) Remove(key string) bool

Remove removes the element with the specified key

func (*String) RemoveAt added in v0.25.12

func (x *String) RemoveAt(index int) bool

RemoveAt removes the element at the specified index

func (String) Reverse added in v0.10.0

func (x String) Reverse() String

Reverse modifies the slice with the elements in reverse order

func (*String) SetIndex added in v0.24.0

func (x *String) SetIndex(index int, value any) bool

SetIndex sets the value at the specified index

func (*String) SetString

func (x *String) SetString(key string, value string) bool

SetString sets the string value at the specified key

func (*String) SetValue added in v0.10.0

func (x *String) SetValue(value any) error

SetValue sets the value of this slice to the provided value

func (String) Shuffle added in v0.21.4

func (x String) Shuffle() String

Shuffle randomizes the order of the elements in the slice

Jump to

Keyboard shortcuts

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