ucontainer

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: BSD-3-Clause Imports: 0 Imported by: 0

Documentation

Overview

Package ucontainer extends container and implements generic container types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Memo

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

Memo holds a cached value.

func NewMemo

func NewMemo[T any](update func() T) Memo[T]

NewMemo creates a new Memo which will take its value from the specified update callback.

func (*Memo[T]) Invalidate

func (this *Memo[T]) Invalidate()

Invalidate marks the Memo's value as invalid, which will cause it to be updated the next time Value is called.

func (*Memo[T]) Value

func (this *Memo[T]) Value() T

Value returns the Memo's value, updating it if the current cached value is invalid.

type Optional added in v0.3.0

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

Optional can either hold a value, or nothing.

func O added in v0.4.0

func O[T any](value T) Optional[T]

O creates a new optional with the specified value.

func Void added in v0.4.0

func Void[T any]() Optional[T]

Void returns an optional with no value.

func (Optional[T]) Exists added in v0.3.0

func (optional Optional[T]) Exists() bool

Exists returns if the value is currently set.

func (Optional[T]) Value added in v0.3.0

func (optional Optional[T]) Value() (T, bool)

Value returns the value and true if the value exists. If not, it returns the zero value and false.

type Set

type Set[T comparable] map[T]struct{}

Set is a set of unique items, built on top of map.

func NewSet added in v0.4.0

func NewSet[T comparable](items ...T) Set[T]

NewSet creates a new set that contains all specified items.

func (Set[T]) Add

func (set Set[T]) Add(item T)

Add adds an item to the set.

func (Set[T]) Empty

func (set Set[T]) Empty() bool

Empty returns true if there are no items in the set.

func (Set[T]) Has

func (set Set[T]) Has(item T) bool

Has returns true if the set contains item.

func (Set[T]) Pop

func (set Set[T]) Pop() (item T)

Pop removes the first accessible item from the set and returns it.

Jump to

Keyboard shortcuts

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