set

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2022 License: MIT Imports: 5 Imported by: 0

README

Package set

set.

Usage

example

package main

import (
	"log"

	"github.com/QisFj/godry/set"
)

func main() {
	log.Println("Int Set:")
	intSet()
	log.Println("String Set:")
	stringSet()
}

func intSet() {
	s := set.Of(1, 1, 1, 2, 2, 2)
	log.Printf("set list: %v\n", s.List())
}

func stringSet() {
	s := set.Of("1", "1", "1", "2", "2", "2")
	log.Printf("set list: %v\n", s.List())
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MarshalOrder = 0

MarshalOrder can change the order of the elements when marshaling. 1 for desc 2 for asc 0 or other value for no certain order

Functions

func AscLess added in v0.2.7

func AscLess[V constraints.Ordered](v1, v2 V) bool

func DescLess added in v0.2.7

func DescLess[V constraints.Ordered](v1, v2 V) bool

Types

type Set added in v0.2.0

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

func Diff added in v0.2.0

func Diff[V comparable](s1, s2 Set[V]) (both, only1, only2 Set[V])

func Intersect added in v0.2.2

func Intersect[V comparable](s1, s2 Set[V]) Set[V]

func Of added in v0.2.0

func Of[V comparable](values ...V) Set[V]

func Subtract added in v0.2.0

func Subtract[V comparable](s1, s2 Set[V]) Set[V]

func Union added in v0.2.0

func Union[V comparable](s1, s2 Set[V]) Set[V]

func (*Set[V]) Add added in v0.2.0

func (s *Set[V]) Add(values ...V)

func (Set[V]) AddSet added in v0.2.0

func (s Set[V]) AddSet(another Set[V])

func (Set[V]) Clone added in v0.2.0

func (s Set[V]) Clone() Set[V]

func (Set[V]) Contains added in v0.2.0

func (s Set[V]) Contains(value V) bool

func (Set[V]) ContainsAll added in v0.2.0

func (s Set[V]) ContainsAll(values ...V) bool

func (Set[V]) ContainsAllOfSet added in v0.2.0

func (s Set[V]) ContainsAllOfSet(another Set[V]) bool

func (Set[V]) ContainsAny added in v0.2.0

func (s Set[V]) ContainsAny(values ...V) bool

func (Set[V]) ContainsAnyOfSet added in v0.2.0

func (s Set[V]) ContainsAnyOfSet(another Set[V]) bool

func (Set[V]) List added in v0.2.0

func (s Set[V]) List() []V

func (Set[V]) MarshalJSON added in v0.2.0

func (s Set[V]) MarshalJSON() ([]byte, error)

func (*Set[V]) Remove added in v0.2.0

func (s *Set[V]) Remove(values ...V)

func (Set[V]) RemoveSet added in v0.2.0

func (s Set[V]) RemoveSet(another Set[V])

func (*Set[V]) UnmarshalJSON added in v0.2.0

func (s *Set[V]) UnmarshalJSON(data []byte) error

type SortableSet added in v0.2.1

type SortableSet[V constraints.Ordered] map[V]struct{}

func (SortableSet[V]) MarshalJSON added in v0.2.1

func (s SortableSet[V]) MarshalJSON() ([]byte, error)

func (SortableSet[V]) OrderedList added in v0.2.7

func (s SortableSet[V]) OrderedList(less func(v1, v2 V) bool) []V

OrderedList return an ordered list can use AscLess, DescLess as less function

func (*SortableSet[V]) UnmarshalJSON added in v0.2.1

func (s *SortableSet[V]) UnmarshalJSON(data []byte) error

type T

type T struct {
	// contains filtered or unexported fields
}

func NewT

func NewT(t reflect.Type) T

func TDiff

func TDiff(s1, s2 T) (both, only1, only2 T)

func TIntersect added in v0.2.2

func TIntersect(s1, s2 T) T

func TSubtract added in v0.2.0

func TSubtract(s1, s2 T) T

func TUnion added in v0.2.0

func TUnion(s1, s2 T) T

func (*T) Add

func (set *T) Add(es ...interface{})

func (*T) AddSet added in v0.2.0

func (set *T) AddSet(another T)

func (T) Clone added in v0.2.0

func (set T) Clone() T

func (T) Contains

func (set T) Contains(e interface{}) bool

func (T) ContainsAll

func (set T) ContainsAll(es ...interface{}) bool

func (T) ContainsAny

func (set T) ContainsAny(es ...interface{}) bool

func (T) List

func (set T) List() interface{}

func (*T) New

func (set *T) New(t reflect.Type)

func (*T) Remove added in v0.2.0

func (set *T) Remove(es ...interface{})

func (*T) RemoveSet added in v0.2.0

func (set *T) RemoveSet(another T)

Jump to

Keyboard shortcuts

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