match

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2025 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Act

func Act[T any](v T, a Action) act[T]

func ActFn

func ActFn[T any](s int, fn func(T) bool, a Action) actFn[T]

func IsZero

func IsZero[T any](val T) (ok bool)

func Pop

func Pop[T any](arr []T) (res T, out []T, ok bool)

func Shift

func Shift[T any](arr []T) (res T, out []T, ok bool)

func Split

func Split[Arr, Item any](itr Iter[Arr, Item], match Match[Window[Arr], SplitResult[Arr]]) (result []Arr)

Types

type Action

type Action int
const (
	Nothing Action = iota
	Replaces
	Deletes
	Stops

	Keep
	Skip
)

type Eq

type Eq[T any] func(T, T) bool

type Index

type Index[Src, Item any] func(src Src, idx int) (result Item, ok bool)

type Iter

type Iter[Arr, Item any] interface {
	Index(idx int) (Item, bool)
	Slice(from, to int) (Arr, bool)
	Step(n int) (Item, bool)
	Window(n int) (Arr, bool)
	Iter() iter.Seq2[int, Item]
	Reverse() Iter[Arr, Item]
	I() int
}

func ToIter

func ToIter[Arr string | []Item, Item any | rune | byte | string](input Arr) (res Iter[Arr, Item], err error)

func ToIterBy

func ToIterBy[Src, Arr, Item any](input Src, idx Index[Src, Item], rng Range[Src, Arr]) Iter[Arr, Item]

type Match

type Match[Source, Result any] func(Source) Result

func Is

func Is[T any](sizer Size[T], eq Eq[T], items ...act[T]) (res Match[Window[T], SplitResult[T]])

func IsBy

func IsBy[T any](items ...actFn[T]) (res Match[Window[T], SplitResult[T]])

func Until

func Until[T any](until bool, fn func(T) bool, action Action) (res Match[Window[T], SplitResult[T]])

type Range

type Range[Src, Arr any] func(src Src, from int, to int) (result Arr, ok bool)

type Size

type Size[T any] func(item T) (size int)

func (Size[T]) Eq

func (s Size[T]) Eq(a, b T) int

type SplitArguments

type SplitArguments[T any] struct {
	Window[T]
	Size[T]
	Eq[T]
	Action
}

type SplitResult

type SplitResult[T any] struct {
	Result T
	Size   int
	Ok     bool
	Action
}

type Window

type Window[T any] func(size int) (result T, ok bool)

Jump to

Keyboard shortcuts

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