-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd.go
61 lines (53 loc) · 1.25 KB
/
add.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
49
50
51
52
53
54
55
56
57
58
59
60
61
package golist
import "github.com/emylincon/golist/core"
// Add :
// adds two list together and returns new list and possible error
func (arr *List) Add(other *List) (newList *List, err error) {
if arr.Type() != other.Type() {
return nil, ErrListsNotOfSameType
} else if arr.Type() == TypeListUnknown {
return nil, ErrTypeNotsupported
}
err = nil
switch list := arr.list.(type) {
case []int:
otherList, ok := other.list.([]int)
if !ok {
return
}
newList = NewList(core.ExtendInt(&list, otherList))
case []int32:
otherList, ok := other.list.([]int32)
if !ok {
return
}
newList = NewList(core.ExtendInt32(&list, otherList))
case []int64:
otherList, ok := other.list.([]int64)
if !ok {
return
}
newList = NewList(core.ExtendInt64(&list, otherList))
case []float32:
otherList, ok := other.list.([]float32)
if !ok {
return
}
newList = NewList(core.ExtendFloat32(&list, otherList))
case []float64:
otherList, ok := other.list.([]float64)
if !ok {
return
}
newList = NewList(core.ExtendFloat64(&list, otherList))
case []string:
otherList, ok := other.list.([]string)
if !ok {
return
}
newList = NewList(core.ExtendString(&list, otherList))
default:
return nil, ErrTypeNotsupported
}
return
}