base

package
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2022 License: MIT Imports: 4 Imported by: 10

Documentation

Overview

Package base 基础类型.

包括Map, Set, Slice, JSNumber.

Index

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的数值.

func Panic added in v1.1.1

func Panic(err error)

Panic 恐慌.

func Panic1 added in v1.1.1

func Panic1[T any](t T, err error) T

Panic1 恐慌1. nolint: ireturn

func Panic2 added in v1.1.1

func Panic2[T1, T2 any](t1 T1, t2 T2, err error) (T1, T2)

Panic2 恐慌2. nolint: ireturn

func Panic3 added in v1.1.1

func Panic3[T1, T2, T3 any](t1 T1, t2 T2, t3 T3, err error) (T1, T2, T3)

Panic3 恐慌3. nolint: ireturn

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]

func (Map[K, V]) All

func (m Map[K, V]) All(keys ...K) bool

func (Map[K, V]) Any

func (m Map[K, V]) Any(keys ...K) bool

func (Map[K, V]) Del

func (m Map[K, V]) Del(keys ...K)

func (Map[K, V]) DelMap

func (m Map[K, V]) DelMap(elems ...Map[K, V])

func (Map[K, V]) Has

func (m Map[K, V]) Has(key K) bool

func (Map[K, V]) Keys

func (m Map[K, V]) Keys() []K

func (Map[K, V]) Put

func (m Map[K, V]) Put(elems ...Map[K, V])

func (Map[K, V]) String

func (m Map[K, V]) String() string

String 字符串.

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

func NewSet

func NewSet[K comparable](elems ...K) Set[K]

NewSet 新建set.

func (Set[K]) Add

func (set Set[K]) Add(elems ...K) Set[K]

Add 增加.

func (Set[K]) AddSet

func (set Set[K]) AddSet(elems ...Set[K]) Set[K]

AddSet 增加set.

func (Set[K]) All

func (set Set[K]) All(keys ...K) bool

All 包含全部.

func (Set[K]) Any

func (set Set[K]) Any(keys ...K) bool

Any 包含任意个.

func (Set[K]) Del

func (set Set[K]) Del(keys ...K) Set[K]

Del 删除.

func (Set[K]) DelSet

func (set Set[K]) DelSet(elems ...Set[K]) Set[K]

DelSet 删除set.

func (Set[K]) Has

func (set Set[K]) Has(key K) bool

Has 包含.

func (Set[K]) Join

func (set Set[K]) Join(sep string) string

Join 集合连接.

func (Set[K]) Slice

func (set Set[K]) Slice() []K

Slice 转换切片.

func (Set[K]) String

func (set Set[K]) String() string

String 字符串.

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]

func (*Slice[T]) Add

func (s *Slice[T]) Add(elems ...T) Slice[T]

func (Slice[T]) All

func (s Slice[T]) All(elems ...T) bool

All 全部包含.

func (Slice[T]) Any

func (s Slice[T]) Any(elems ...T) bool

Any 任意包含.

func (*Slice[T]) Del

func (s *Slice[T]) Del(elems ...T) Slice[T]

Del 删除.

func (*Slice[T]) DelAll

func (s *Slice[T]) DelAll(elems ...T) Slice[T]

DelAll 删除全部.

func (Slice[T]) Has

func (s Slice[T]) Has(elem T) bool

Has 包含.

func (Slice[T]) Index

func (s Slice[T]) Index(elem T) int

Index 位置.

func (Slice[T]) Join

func (s Slice[T]) Join(sep string) string

Join 集合连接.

func (Slice[T]) Len

func (s Slice[T]) Len() int

func (Slice[T]) Less

func (s Slice[T]) Less(i, j int) bool

func (Slice[T]) String

func (s Slice[T]) String() string

String 转换成字符串.

func (Slice[T]) Swap

func (s Slice[T]) Swap(i, j int)

Jump to

Keyboard shortcuts

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