slices

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2024 License: MIT Imports: 2 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter added in v0.1.2

func Filter[S ~[]E, E any](s *S, predicate Predicate[E]) uint

Filter filters a slice of E's according to a predicate.

Parameters:

  • s: The slice of E's to filter.
  • predicate: The predicate to use for filtering.

Returns:

  • uint: The number of elements filtered-out.

Panics:

  • common.ErrBadParam: If the predicate is nil.

func Reject added in v0.1.2

func Reject[S ~[]E, E any](s *S, predicate Predicate[E]) uint

Reject rejects a slice of E's according to a predicate.

Parameters:

  • s: The slice of E's to reject.
  • predicate: The predicate to use for rejecting.

Returns:

  • uint: The number of elements rejected.

Panics:

  • common.ErrBadParam: If the predicate is nil.

func RejectNils

func RejectNils[S ~[]*E, E any](s *S) uint

RejectNils rejects in-place all nil elements from a slice of E's and returns the number of elements rejected.

Parameters:

  • s: The slice of E's to filter.

Returns:

  • uint: The number of elements rejected.

func RejectZero added in v0.1.7

func RejectZero[S ~[]E, E comparable](s *S) uint

RejectZero rejects in-place all zero-valued elements from a slice of E's and returns the number of elements rejected.

Parameters:

  • s: The slice of E's to filter.

Returns:

  • uint: The number of elements rejected.

Types

type Builder added in v0.1.1

type Builder[E any] struct {
	// contains filtered or unexported fields
}

Builder is a builder for slices. It is only efficent for making many slices one after the other.

An empty builder can be created with the `var b Builder[T]` syntax or with the `new(Builder[T])` constructor.

func (*Builder[E]) Append added in v0.1.1

func (b *Builder[E]) Append(elem E) error

Append appends an element to the slice being built.

Parameters:

  • elem: The element to append.

Returns:

  • error: An error if the element could not be appended.

Errors:

  • common.ErrNilReceiver: If the receiver is nil.

func (Builder[E]) Build added in v0.1.1

func (b Builder[E]) Build() []E

Build builds the slice being built.

Returns:

  • []E: The slice being built.

func (*Builder[E]) Reset added in v0.1.1

func (b *Builder[E]) Reset() error

Reset resets the builder to its initial state, freeing up any allocated memory so that it can be reused to build another slice. This is more efficient than creating a new builder if you need to build many slices in a row.

Returns:

  • error: An error if the builder is nil.

Errors:

  • errors.ErrNilReceiver: If the receiver is nil.

type Predicate

type Predicate[E any] func(e E) bool

Predicate is a function that returns true if the element is valid.

Parameters:

  • e: The element to check.

Returns:

  • bool: True if the element is valid, false otherwise.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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