Documentation ¶
Overview ¶
Package base 基础类型.
包括Map, Set, Slice, JSNumber.
Index ¶
- Variables
- func JSNumber[Num constraints.Integer | constraints.Float](num Num) Num
- func Panic(err error)
- func Panic1[T any](t T, err error) T
- func Panic2[T1, T2 any](t1 T1, t2 T2, err error) (T1, T2)
- func Panic3[T1, T2, T3 any](t1 T1, t2 T2, t3 T3, err error) (T1, T2, T3)
- type Map
- func (m Map[K, V]) All(keys ...K) bool
- func (m Map[K, V]) Any(keys ...K) bool
- func (m Map[K, V]) Del(keys ...K)
- func (m Map[K, V]) DelMap(elems ...Map[K, V])
- func (m Map[K, V]) Has(key K) bool
- func (m Map[K, V]) Keys() []K
- func (m Map[K, V]) Put(elems ...Map[K, V])
- func (m Map[K, V]) String() string
- type Set
- func (set Set[K]) Add(elems ...K) Set[K]
- func (set Set[K]) AddSet(elems ...Set[K]) Set[K]
- func (set Set[K]) All(keys ...K) bool
- func (set Set[K]) Any(keys ...K) bool
- func (set Set[K]) Del(keys ...K) Set[K]
- func (set Set[K]) DelSet(elems ...Set[K]) Set[K]
- func (set Set[K]) Has(key K) bool
- func (set Set[K]) Join(sep string) string
- func (set Set[K]) Slice() []K
- func (set Set[K]) String() string
- type Slice
- func (s *Slice[T]) Add(elems ...T) Slice[T]
- func (s Slice[T]) All(elems ...T) bool
- func (s Slice[T]) Any(elems ...T) bool
- func (s *Slice[T]) Del(elems ...T) Slice[T]
- func (s *Slice[T]) DelAll(elems ...T) Slice[T]
- func (s Slice[T]) Has(elem T) bool
- func (s Slice[T]) Index(elem T) int
- func (s Slice[T]) Join(sep string) string
- func (s Slice[T]) Len() int
- func (s Slice[T]) Less(i, j int) bool
- func (s Slice[T]) String() string
- func (s Slice[T]) Swap(i, j int)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var None struct{} // nolint: gochecknoglobals
None 无值.
Functions ¶
func JSNumber ¶
func JSNumber[Num constraints.Integer | constraints.Float](num Num) Num
JSNumber 装换成兼容JS的数值.
Types ¶
type Map ¶
type Map[K comparable, V any] map[K]V
Example ¶
package main import ( "fmt" "gitee.com/xuender/oils/base" ) func main() { map1 := base.NewMap[int, int]() map1[1] = 2 map1[3] = 5 fmt.Println(len(map1)) }
Output: 2
func NewMap ¶
func NewMap[K comparable, V any]() Map[K, V]
type Set ¶
type Set[K comparable] map[K]struct{}
Set 通用set.
Example ¶
package main import ( "fmt" "gitee.com/xuender/oils/base" ) func main() { set := base.NewSet(1, 2, 2) set.Add(3) fmt.Println(len(set)) fmt.Println(set.Any(7, 2)) fmt.Println(set.All(7, 2)) set.Del(1) fmt.Println(len(set)) }
Output: 3 true false 2
type Slice ¶
type Slice[T constraints.Ordered] []T
Example ¶
package main import ( "fmt" "sort" "gitee.com/xuender/oils/base" ) func main() { str := base.NewSlice("c", "a") sort.Sort(str) fmt.Println(str[0]) fmt.Println(str[1]) fmt.Println(str.All("a", "b")) fmt.Println(str.Any("a", "b")) fmt.Println(str.Has("b")) fmt.Println(str.Index("c")) fmt.Println(str.Index("b")) fmt.Println(str) }
Output: a c false true false 1 -1 Slice[a c]
func NewSlice ¶
func NewSlice[T constraints.Ordered](elems ...T) Slice[T]
Click to show internal directories.
Click to hide internal directories.