-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcommon.go
48 lines (42 loc) · 1.39 KB
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package gofp
import (
"math/rand"
"time"
)
//Randomer returns a Rand with seed which helps to generate unique randome numbers each time
func Randomer() *rand.Rand {
seed := rand.NewSource(time.Now().UnixNano())
return rand.New(seed)
}
//StringToInterfaceSlice converts a slice of string to slice of interface
func StringToInterfaceSlice(stringSlice []string) []interface{} {
interfaceSlice := make([]interface{}, len(stringSlice), len(stringSlice))
for i := range stringSlice {
interfaceSlice[i] = stringSlice[i]
}
return interfaceSlice
}
//StringSlice converts a slice of interface to slice of string
func StringSlice(interfaceSlice []interface{}) []string {
stringSlice := make([]string, len(interfaceSlice), len(interfaceSlice))
for i := range interfaceSlice {
stringSlice[i] = interfaceSlice[i].(string)
}
return stringSlice
}
//IntSlice converts a slice of interface to slice of int
func IntSlice(interfaceSlice []interface{}) []int {
intSlice := make([]int, len(interfaceSlice), len(interfaceSlice))
for i := range interfaceSlice {
intSlice[i] = interfaceSlice[i].(int)
}
return intSlice
}
//Float64Slice converts a slice of interface to slice of int
func Float64Slice(interfaceSlice []interface{}) []float64 {
float64Slice := make([]float64, len(interfaceSlice), len(interfaceSlice))
for i := range interfaceSlice {
float64Slice[i] = interfaceSlice[i].(float64)
}
return float64Slice
}