@@ -19,8 +19,8 @@ func init() {
19
19
py .MustNewMethod ("__build_class__" , builtin___build_class__ , 0 , build_class_doc ),
20
20
py .MustNewMethod ("__import__" , py .InternalMethodImport , 0 , import_doc ),
21
21
py .MustNewMethod ("abs" , builtin_abs , 0 , abs_doc ),
22
- // py.MustNewMethod("all", builtin_all, 0, all_doc),
23
- // py.MustNewMethod("any", builtin_any, 0, any_doc),
22
+ py .MustNewMethod ("all" , builtin_all , 0 , all_doc ),
23
+ py .MustNewMethod ("any" , builtin_any , 0 , any_doc ),
24
24
// py.MustNewMethod("ascii", builtin_ascii, 0, ascii_doc),
25
25
// py.MustNewMethod("bin", builtin_bin, 0, bin_doc),
26
26
// py.MustNewMethod("callable", builtin_callable, 0, callable_doc),
@@ -225,6 +225,63 @@ func builtin_abs(self, v py.Object) (py.Object, error) {
225
225
return py .Abs (v )
226
226
}
227
227
228
+ const all_doc = `all(iterable) -> bool
229
+
230
+ Return True if bool(x) is True for all values x in the iterable.
231
+ If the iterable is empty, return True.
232
+ `
233
+
234
+ func builtin_all (self , seq py.Object ) (py.Object , error ) {
235
+ iter , err := py .Iter (seq )
236
+ res := false
237
+ if err != nil {
238
+ return nil , err
239
+ }
240
+ for {
241
+ item , err := py .Next (iter )
242
+ if err != nil {
243
+ if py .IsException (py .StopIteration , err ) {
244
+ break
245
+ }
246
+ return nil , err
247
+ }
248
+ if py .ObjectIsTrue (item ) {
249
+ res = true
250
+ } else {
251
+ res = false
252
+ break
253
+ }
254
+ }
255
+ return py .NewBool (res ), nil
256
+ }
257
+
258
+ const any_doc = `any(iterable) -> bool
259
+
260
+ Return True if bool(x) is True for any x in the iterable.
261
+ If the iterable is empty, Py_RETURN_FALSE."`
262
+
263
+ func builtin_any (self , seq py.Object ) (py.Object , error ) {
264
+ iter , err := py .Iter (seq )
265
+ res := false
266
+ if err != nil {
267
+ return nil , err
268
+ }
269
+ for {
270
+ item , err := py .Next (iter )
271
+ if err != nil {
272
+ if py .IsException (py .StopIteration , err ) {
273
+ break
274
+ }
275
+ return nil , err
276
+ }
277
+ if py .ObjectIsTrue (item ) {
278
+ res = true
279
+ break
280
+ }
281
+ }
282
+ return py .NewBool (res ), nil
283
+ }
284
+
228
285
const round_doc = `round(number[, ndigits]) -> number
229
286
230
287
Round a number to a given precision in decimal digits (default 0 digits).
0 commit comments