slices

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package slices implements the functions, types, and interfaces for the module.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTooLarge is an error when number is too large than length
	ErrTooLarge = errors.New("slices.Array: number is too large than length")
	// ErrTooSmall is an error when number is too small than length
	ErrTooSmall = errors.New("slices.Array: number is too small than length")
	// ErrWrongIndex is an error when index is out of range
	ErrWrongIndex = errors.New("slices.Array: wrong index")
)

Functions

func Append

func Append[T types.Slice[S], S E](arr T, v S) (T, int)

Append appends the element v to the end of Array[S] s.

func Contains

func Contains[T types.Slice[S], S E](s, sub T) bool

Contains reports whether substr is within s.

func ContainsArray

func ContainsArray[T types.Slice[S], S E](s T, e S) bool

ContainsArray reports whether any Unicode code points in chars are within s.

func CopyAt

func CopyAt[T types.Slice[S], S E](s, t T, i int) T

func Count

func Count[T types.Slice[S], S E](s, sub T) int

Count counts the number of non-overlapping instances of substr in s. If substr is an empty Array, Count returns 1 + the number of Unicode code points in s.

func CountArray

func CountArray[T types.Slice[S], S E](ss T, s S) int

CountArray counts the number of non-overlapping instances of c in s.

func Cut

func Cut[T types.Slice[S], S E](s, sep T) (before, after T, found bool)

Cut slices s around the first instance of sep, returning the text before and after sep. The found result reports whether sep appears in s. If sep does not appear in s, cut returns s, "", false.

func Equal

func Equal[T types.Slice[S], S E](a, b T) bool

Equal reports whether a and b are the same length and contain the same runes. A nil argument is equivalent to an empty slice.

func HasPrefix

func HasPrefix[T types.Slice[S], S E](s, prefix T) bool

HasPrefix tests whether the Array[S] s begins with prefix.

func HasSuffix

func HasSuffix[T types.Slice[S], S E](s, suffix T) bool

HasSuffix tests whether the Array[S] s ends with suffix.

func Index

func Index[T types.Slice[S], S E](s, sep T) int

Index returns the index of the first instance of substr in s, or -1 if substr is not present in s.

func IndexArray

func IndexArray[T types.Slice[S], S E](s T, r S) int

IndexArray returns the index of the first instance of the runes point r, or -1 if rune is not present in s.

func InsertWith

func InsertWith[T types.Slice[S], S E](s T, v S, fn func(a, b S) bool) T

InsertWith inserts v into s at the first index where fn(a, b) is true.

func Join

func Join[T types.Slice[S], S E](s []T, sep T) T

Join concatenates the elements of its first argument to create a single Array[S]. The separator Array[S] sep is placed between elements in the resulting Array[S].

func LastIndex

func LastIndex[T types.Slice[S], S E](s, sep T) int

LastIndex returns the index of the last instance of substr in s, or -1 if substr is not present in s.

func LastIndexArray

func LastIndexArray[T types.Slice[S], S E](s T, c S) int

LastIndexArray returns the index of the last instance of c in s, or -1 if c is not present in s.

func OverWithError

func OverWithError[S any](s []S, err error) func(func(int, S) bool)

func Read

func Read[T types.Slice[S], S E](arr T, offset int, limit int) T

Read returns a slice of the Array[S] s beginning at offset and length limit. If offset or limit is negative, it is treated as if it were zero.

func RemoveWith

func RemoveWith[T types.Slice[S], S E](s T, fn func(a S) bool) T

RemoveWith removes the first index where fn(a, b) is true.

func Repeat

func Repeat[T types.Slice[S], S E](b T, count int) T

Repeat returns a new Array[S] consisting of count copies of the Array[S] s.

It panics if count is negative or if the result of (len(s) * count) overflows.

func Transform added in v0.2.5

func Transform[TS types.Slice[S], S any, T any](s TS, f func(S) (T, bool)) []T

Types

type Bytes

type Bytes []byte

func StringToBytes

func StringToBytes(s string) Bytes

func (Bytes) FindString

func (r Bytes) FindString(s string) int

func (Bytes) Index

func (r Bytes) Index(sub []byte) int

func (Bytes) Read

func (r Bytes) Read(offset int, limit int) Bytes

func (Bytes) ReadString

func (r Bytes) ReadString(offset int, limit int) string

func (Bytes) String

func (r Bytes) String() string

func (Bytes) StringArray

func (r Bytes) StringArray() []string

type E

type E = comparable

E is comparable type of slice element

type Runes

type Runes []rune

func StringToRunes

func StringToRunes(s string) Runes

func (Runes) FindString

func (r Runes) FindString(s string) int

func (Runes) Index

func (r Runes) Index(sub []rune) int

func (Runes) Read

func (r Runes) Read(offset int, limit int) Runes

func (Runes) ReadString

func (r Runes) ReadString(offset int, limit int) string

func (Runes) String

func (r Runes) String() string

func (Runes) StringArray

func (r Runes) StringArray() []string

type Slicer added in v0.2.5

type Slicer[T any] interface {
	~[]T
}

Jump to

Keyboard shortcuts

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