Documentation
¶
Overview ¶
Package rslices - slices functions.
Index ¶
- func Add[T constraints.Float](x, y []T)
- func AddNum[S ~[]E, E constraints.Float](x S, a E)
- func Concat[S ~[]E, E any](collections ...S) S
- func Intersection[T cmp.Ordered](s1, s2 []T) []T
- func IsIntersect[E comparable](s1, s2 []E) bool
- func MaximumNum[S ~[]E, E constraints.Float](x S, a E)
- func Mul[T constraints.Float](x, y []T)
- func MulNum[S ~[]E, E constraints.Float](x S, a E)
- func Sum[T constraints.Float | constraints.Integer | constraints.Complex](collection []T) T
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Add ¶
func Add[T constraints.Float](x, y []T)
Add - adding slice x to slice y.
Example ¶
var (
s32_1 = []float32{1, 2, 3}
s32_2 = []float32{2, 2, 2}
s64_1 = []float64{1, 2, 3}
s64_2 = []float64{2, 2, 2}
)
Add(s32_1, s32_2)
fmt.Println(s32_1)
Add(s64_1, s64_2)
fmt.Println(s64_1)
Output: [3 4 5] [3 4 5]
func AddNum ¶
func AddNum[S ~[]E, E constraints.Float](x S, a E)
AddNum - adding slice x by a.
Example ¶
var (
s32_1 = []float32{1, 2, 3}
num_32 float32 = 2
s64_1 = []float64{1, 2, 3}
num_64 float64 = 2
)
AddNum(s32_1, num_32)
fmt.Println(s32_1)
AddNum(s64_1, num_64)
fmt.Println(s64_1)
Output: [3 4 5] [3 4 5]
func Concat ¶ added in v1.1.14
func Concat[S ~[]E, E any](collections ...S) S
Concat - concatenation two slices.
Example ¶
var (
ints1 = []int{1, 2, 3}
ints2 = []int{4, 5, 6}
ints3 = []int{7, 8, 9}
strs1 = []string{"1", "2", "3"}
strs2 = []string{"4", "5", "6"}
strs3 = []string{"7", "8", "9"}
)
ints := Concat(ints1, ints2, ints3)
fmt.Println(ints)
strs := Concat(strs1, strs2, strs3)
fmt.Println(strs)
Output: [1 2 3 4 5 6 7 8 9] [1 2 3 4 5 6 7 8 9]
func Intersection ¶ added in v1.1.14
Intersection - intersection of two arrays. Returns new slice.
Example ¶
var (
intsL = []int{1, 2, 3}
intsR = []int{1, 2, 4}
floatsL = []float64{1.1, 2.2, 3.3}
floatsR = []float64{1.1, 2.2, 4.4}
strL = []string{"aaa", "bbb", "ccc"}
strR = []string{"aaa", "bbb", "ddd"}
)
resInts := Intersection(intsL, intsR)
fmt.Println(resInts)
resFloats := Intersection(floatsL, floatsR)
fmt.Println(resFloats)
resStrs := Intersection(strL, strR)
fmt.Println(resStrs)
Output: [1 2] [1.1 2.2] [aaa bbb]
func IsIntersect ¶ added in v1.1.14
func IsIntersect[E comparable](s1, s2 []E) bool
IsIntersect - return ok or not for intersection slice.
Example ¶
var (
ints1 = []int{1, 2, 3}
ints2 = []int{3, 4, 5}
floats1 = []float64{1.1, 2.2, 3.3}
floats2 = []float64{11.1, 22.2, 44.4}
str1 = []string{"aaa", "bbb", "ccc"}
str2 = []string{"aaa", "bbb", "ddd"}
)
resInts := IsIntersect(ints1, ints2)
fmt.Println(resInts)
resFloats := IsIntersect(floats1, floats2)
fmt.Println(resFloats)
resStrs := IsIntersect(str1, str2)
fmt.Println(resStrs)
Output: true false true
func MaximumNum ¶
func MaximumNum[S ~[]E, E constraints.Float](x S, a E)
MaximumNum - set 0 if a < 0.
Example ¶
var (
s32_1 = []float32{1, 2, 3}
num_32 float32 = 2
s64_1 = []float64{1, 2, 3}
num_64 float64 = 2
)
MaximumNum(s32_1, num_32)
fmt.Println(s32_1)
MaximumNum(s64_1, num_64)
fmt.Println(s64_1)
Output: [0 2 3] [0 2 3]
func Mul ¶
func Mul[T constraints.Float](x, y []T)
Mul - multiplying slice x by slice y.
Example ¶
var (
s32_1 = []float32{1, 2, 3}
s32_2 = []float32{2, 2, 2}
s64_1 = []float64{1, 2, 3}
s64_2 = []float64{2, 2, 2}
)
Mul(s32_1, s32_2)
fmt.Println(s32_1)
Mul(s64_1, s64_2)
fmt.Println(s64_1)
Output: [2 4 6] [2 4 6]
func MulNum ¶
func MulNum[S ~[]E, E constraints.Float](x S, a E)
MulNum - multiplying slice x by a.
Example ¶
var (
s32_1 = []float32{1, 2, 3}
num_32 float32 = 2
s64_1 = []float64{1, 2, 3}
num_64 float64 = 2
)
MulNum(s32_1, num_32)
fmt.Println(s32_1)
MulNum(s64_1, num_64)
fmt.Println(s64_1)
Output: [2 4 6] [2 4 6]
func Sum ¶
func Sum[T constraints.Float | constraints.Integer | constraints.Complex](collection []T) T
Sum - sums the values in a collection. If collection is empty 0 is returned.
Example ¶
var (
s32 = []float32{1, 2, 3}
s64 = []float64{1, 2, 3}
)
resFloats32 := Sum(s32)
fmt.Println(resFloats32)
resFloats64 := Sum(s64)
fmt.Println(resFloats64)
Output: 6 6
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.