@@ -6,168 +6,164 @@ import (
6
6
"strconv"
7
7
)
8
8
9
- func Len (xs ... interface {}) (interface {}, error ) {
10
- x := xs [0 ]
9
+ func Len (x interface {}) interface {} {
11
10
v := reflect .ValueOf (x )
12
11
switch v .Kind () {
13
12
case reflect .Array , reflect .Slice , reflect .Map , reflect .String :
14
- return v .Len (), nil
13
+ return v .Len ()
15
14
default :
16
- return nil , fmt .Errorf ("invalid argument for len (type %T)" , x )
15
+ panic ( fmt .Sprintf ("invalid argument for len (type %T)" , x ) )
17
16
}
18
17
}
19
18
20
- func Abs (xs ... interface {}) (interface {}, error ) {
21
- x := xs [0 ]
19
+ func Abs (x interface {}) interface {} {
22
20
switch x .(type ) {
23
21
case float32 :
24
22
if x .(float32 ) < 0 {
25
- return - x .(float32 ), nil
23
+ return - x .(float32 )
26
24
} else {
27
- return x , nil
25
+ return x
28
26
}
29
27
case float64 :
30
28
if x .(float64 ) < 0 {
31
- return - x .(float64 ), nil
29
+ return - x .(float64 )
32
30
} else {
33
- return x , nil
31
+ return x
34
32
}
35
33
case int :
36
34
if x .(int ) < 0 {
37
- return - x .(int ), nil
35
+ return - x .(int )
38
36
} else {
39
- return x , nil
37
+ return x
40
38
}
41
39
case int8 :
42
40
if x .(int8 ) < 0 {
43
- return - x .(int8 ), nil
41
+ return - x .(int8 )
44
42
} else {
45
- return x , nil
43
+ return x
46
44
}
47
45
case int16 :
48
46
if x .(int16 ) < 0 {
49
- return - x .(int16 ), nil
47
+ return - x .(int16 )
50
48
} else {
51
- return x , nil
49
+ return x
52
50
}
53
51
case int32 :
54
52
if x .(int32 ) < 0 {
55
- return - x .(int32 ), nil
53
+ return - x .(int32 )
56
54
} else {
57
- return x , nil
55
+ return x
58
56
}
59
57
case int64 :
60
58
if x .(int64 ) < 0 {
61
- return - x .(int64 ), nil
59
+ return - x .(int64 )
62
60
} else {
63
- return x , nil
61
+ return x
64
62
}
65
63
case uint :
66
64
if x .(uint ) < 0 {
67
- return - x .(uint ), nil
65
+ return - x .(uint )
68
66
} else {
69
- return x , nil
67
+ return x
70
68
}
71
69
case uint8 :
72
70
if x .(uint8 ) < 0 {
73
- return - x .(uint8 ), nil
71
+ return - x .(uint8 )
74
72
} else {
75
- return x , nil
73
+ return x
76
74
}
77
75
case uint16 :
78
76
if x .(uint16 ) < 0 {
79
- return - x .(uint16 ), nil
77
+ return - x .(uint16 )
80
78
} else {
81
- return x , nil
79
+ return x
82
80
}
83
81
case uint32 :
84
82
if x .(uint32 ) < 0 {
85
- return - x .(uint32 ), nil
83
+ return - x .(uint32 )
86
84
} else {
87
- return x , nil
85
+ return x
88
86
}
89
87
case uint64 :
90
88
if x .(uint64 ) < 0 {
91
- return - x .(uint64 ), nil
89
+ return - x .(uint64 )
92
90
} else {
93
- return x , nil
91
+ return x
94
92
}
95
93
}
96
- return nil , fmt .Errorf ("invalid argument for abs (type %T)" , x )
94
+ panic ( fmt .Sprintf ("invalid argument for abs (type %T)" , x ) )
97
95
}
98
96
99
- func Int (xs ... interface {}) (interface {}, error ) {
100
- x := xs [0 ]
97
+ func Int (x interface {}) interface {} {
101
98
switch x := x .(type ) {
102
99
case float32 :
103
- return int (x ), nil
100
+ return int (x )
104
101
case float64 :
105
- return int (x ), nil
102
+ return int (x )
106
103
case int :
107
- return x , nil
104
+ return x
108
105
case int8 :
109
- return int (x ), nil
106
+ return int (x )
110
107
case int16 :
111
- return int (x ), nil
108
+ return int (x )
112
109
case int32 :
113
- return int (x ), nil
110
+ return int (x )
114
111
case int64 :
115
- return int (x ), nil
112
+ return int (x )
116
113
case uint :
117
- return int (x ), nil
114
+ return int (x )
118
115
case uint8 :
119
- return int (x ), nil
116
+ return int (x )
120
117
case uint16 :
121
- return int (x ), nil
118
+ return int (x )
122
119
case uint32 :
123
- return int (x ), nil
120
+ return int (x )
124
121
case uint64 :
125
- return int (x ), nil
122
+ return int (x )
126
123
case string :
127
124
i , err := strconv .Atoi (x )
128
125
if err != nil {
129
- return nil , fmt .Errorf ("invalid operation: int(%s)" , x )
126
+ panic ( fmt .Sprintf ("invalid operation: int(%s)" , x ) )
130
127
}
131
- return i , nil
128
+ return i
132
129
default :
133
- return nil , fmt .Errorf ("invalid operation: int(%T)" , x )
130
+ panic ( fmt .Sprintf ("invalid operation: int(%T)" , x ) )
134
131
}
135
132
}
136
133
137
- func Float (xs ... interface {}) (interface {}, error ) {
138
- x := xs [0 ]
134
+ func Float (x interface {}) interface {} {
139
135
switch x := x .(type ) {
140
136
case float32 :
141
- return float64 (x ), nil
137
+ return float64 (x )
142
138
case float64 :
143
- return x , nil
139
+ return x
144
140
case int :
145
- return float64 (x ), nil
141
+ return float64 (x )
146
142
case int8 :
147
- return float64 (x ), nil
143
+ return float64 (x )
148
144
case int16 :
149
- return float64 (x ), nil
145
+ return float64 (x )
150
146
case int32 :
151
- return float64 (x ), nil
147
+ return float64 (x )
152
148
case int64 :
153
- return float64 (x ), nil
149
+ return float64 (x )
154
150
case uint :
155
- return float64 (x ), nil
151
+ return float64 (x )
156
152
case uint8 :
157
- return float64 (x ), nil
153
+ return float64 (x )
158
154
case uint16 :
159
- return float64 (x ), nil
155
+ return float64 (x )
160
156
case uint32 :
161
- return float64 (x ), nil
157
+ return float64 (x )
162
158
case uint64 :
163
- return float64 (x ), nil
159
+ return float64 (x )
164
160
case string :
165
161
f , err := strconv .ParseFloat (x , 64 )
166
162
if err != nil {
167
- return nil , fmt .Errorf ("invalid operation: float(%s)" , x )
163
+ panic ( fmt .Sprintf ("invalid operation: float(%s)" , x ) )
168
164
}
169
- return f , nil
165
+ return f
170
166
default :
171
- return nil , fmt .Errorf ("invalid operation: float(%T)" , x )
167
+ panic ( fmt .Sprintf ("invalid operation: float(%T)" , x ) )
172
168
}
173
169
}
0 commit comments