-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextend.go
60 lines (51 loc) · 1.22 KB
/
extend.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
package golist
import "github.com/emylincon/golist/core"
// Extend : This extends current list with input slice. errors if both underlying lists are not of the same type
func (arr *List) Extend(other interface{}) error {
if arr.Type() != NewList(other).Type() {
return ErrListsNotOfSameType
} else if arr.Type() == TypeListUnknown {
return ErrTypeNotsupported
}
switch list := arr.list.(type) {
case []int:
item, ok := other.([]int)
if !ok {
return ErrTypeNotSame
}
arr.list = core.ExtendInt(&list, item)
case []int32:
item, ok := other.([]int32)
if !ok {
return ErrTypeNotSame
}
arr.list = core.ExtendInt32(&list, item)
case []int64:
item, ok := other.([]int64)
if !ok {
return ErrTypeNotSame
}
arr.list = core.ExtendInt64(&list, item)
case []float32:
item, ok := other.([]float32)
if !ok {
return ErrTypeNotSame
}
arr.list = core.ExtendFloat32(&list, item)
case []float64:
item, ok := other.([]float64)
if !ok {
return ErrTypeNotSame
}
arr.list = core.ExtendFloat64(&list, item)
case []string:
item, ok := other.([]string)
if !ok {
return ErrTypeNotSame
}
arr.list = core.ExtendString(&list, item)
default:
return ErrTypeNotsupported
}
return nil
}