golang

package
v2.22.1 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2024 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package golang provides a set of functions and structures making Go more expressive and concise.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func If

func If[T any](condition bool, trueValue T) T

If returns trueValue if condition is true, otherwise the zero value of T.

func IfElse

func IfElse[T any](condition bool, trueValue, falseValue T) T

IfElse returns trueValue if condition is true, otherwise falseValue.

func LazyIf

func LazyIf[T any](condition bool, trueValueFunc func() T) T

LazyIf returns the result of trueValueFunc if condition is true, otherwise the zero value of T. The function is only called if its result is needed.

func LazyIfElse

func LazyIfElse[T any](condition bool, trueValueFunc, falseValueFunc func() T) T

LazyIfElse returns the result of trueValueFunc if condition is true, otherwise the result of falseValueFunc. The functions are only called if their result is needed.

func Ptr added in v2.22.0

func Ptr[T any](v T) *T

Ptr returns a pointer to a literal. Use for initializations. e.g., var pb *bool = Ptr(true).

func Zero

func Zero[T any]() (result T)

Zero returns the zero value of T.

Types

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

Set is a simple implementation of set of values of type T. It allows to mark the set as immutable to prevent further modifications. It is not thread-safe.

func NewSet

func NewSet[T comparable](values ...T) *Set[T]

NewSet creates a new set with the given values.

func (*Set[T]) Add

func (s *Set[T]) Add(value ...T) *Set[T]

Add adds the given values to the set.

func (*Set[T]) Clone

func (s *Set[T]) Clone() *Set[T]

Clone returns a mutable shallow copy of the set.

func (*Set[T]) Contains

func (s *Set[T]) Contains(value T) bool

Contains returns true if the set contains the given value.

func (*Set[T]) IsEmpty

func (s *Set[T]) IsEmpty() bool

IsEmpty returns true if the set is empty.

func (*Set[T]) IsImmutable

func (s *Set[T]) IsImmutable() bool

IsImmutable returns true if the set is immutable.

func (*Set[T]) MarkImmutable

func (s *Set[T]) MarkImmutable() *Set[T]

MarkImmutable marks the set as immutable.

func (*Set[T]) MergeWith

func (s *Set[T]) MergeWith(other *Set[T]) *Set[T]

MergeWith adds all values from the other set to the set.

func (*Set[T]) Remove

func (s *Set[T]) Remove(value T) *Set[T]

Remove removes the given values from the set.

func (*Set[T]) Size

func (s *Set[T]) Size() int

Size returns the number of elements in the set.

func (*Set[T]) Values

func (s *Set[T]) Values() []T

Values returns all values in the set as a slice. The order of the values is not guaranteed.

Jump to

Keyboard shortcuts

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