@@ -4,18 +4,20 @@ use std::fmt;
4
4
use std:: marker:: PhantomData ;
5
5
use std:: ops:: Deref ;
6
6
7
+ use itertools:: Itertools ;
7
8
use num_bigint:: BigInt ;
8
9
use num_complex:: Complex64 ;
9
10
use num_traits:: ToPrimitive ;
10
11
11
12
use crate :: bytecode;
13
+ use crate :: common:: lock:: { PyRwLock , PyRwLockReadGuard } ;
14
+ use crate :: common:: rc:: PyRc ;
12
15
use crate :: exceptions:: { self , PyBaseExceptionRef } ;
13
16
use crate :: function:: { IntoFuncArgs , IntoPyNativeFunc } ;
14
17
use crate :: obj:: objbuiltinfunc:: PyFuncDef ;
15
18
use crate :: obj:: objbytearray;
16
19
use crate :: obj:: objbytes;
17
- use crate :: obj:: objcode;
18
- use crate :: obj:: objcode:: PyCodeRef ;
20
+ use crate :: obj:: objcode:: { self , PyCodeRef } ;
19
21
use crate :: obj:: objcomplex:: PyComplex ;
20
22
use crate :: obj:: objdict:: { PyDict , PyDictRef } ;
21
23
use crate :: obj:: objfloat:: PyFloat ;
@@ -33,16 +35,13 @@ use crate::obj::objstaticmethod::PyStaticMethod;
33
35
use crate :: obj:: objstr;
34
36
use crate :: obj:: objtuple:: { PyTuple , PyTupleRef } ;
35
37
use crate :: obj:: objtype:: { self , PyType , PyTypeRef } ;
36
- pub use crate :: pyobjectrc:: { PyObjectRc , PyObjectWeak } ;
37
38
use crate :: scope:: Scope ;
38
39
use crate :: slots:: { PyTpFlags , PyTypeSlots } ;
39
40
use crate :: types:: { create_type_with_slots, initialize_types, TypeZoo } ;
40
41
use crate :: vm:: VirtualMachine ;
41
- use rustpython_common:: lock:: { PyRwLock , PyRwLockReadGuard } ;
42
- use rustpython_common:: rc:: PyRc ;
43
42
44
43
pub use crate :: common:: borrow:: BorrowValue ;
45
-
44
+ pub use crate :: pyobjectrc :: { PyObjectRc , PyObjectWeak } ;
46
45
/* Python objects and references.
47
46
48
47
Okay, so each python object itself is an class itself (PyObject). Each
@@ -900,6 +899,34 @@ where
900
899
}
901
900
}
902
901
902
+ pub fn try_iterable_map < F , T , R > (
903
+ vm : & VirtualMachine ,
904
+ obj : & PyObjectRef ,
905
+ mut f : F ,
906
+ ) -> PyResult < Vec < R > >
907
+ where
908
+ T : TryFromObject ,
909
+ F : FnMut ( T ) -> PyResult < R > ,
910
+ {
911
+ match_class ! ( match obj {
912
+ ref l @ PyList => l
913
+ . borrow_value( )
914
+ . iter( )
915
+ . map( |x| f( T :: try_from_object( vm, x. clone( ) ) ?) )
916
+ . try_collect( ) ,
917
+ ref t @ PyTuple => t
918
+ . borrow_value( )
919
+ . iter( )
920
+ . map( |x| f( T :: try_from_object( vm, x. clone( ) ) ?) )
921
+ . try_collect( ) ,
922
+ // TODO: put internal iterable typ
923
+ obj => {
924
+ let iter = PyIterable :: <T >:: try_from_object( vm, obj. clone( ) ) ?;
925
+ iter. iter( vm) ?. map( |x| f( x?) ) . try_collect( )
926
+ }
927
+ } )
928
+ }
929
+
903
930
impl TryFromObject for PyObjectRef {
904
931
#[ inline]
905
932
fn try_from_object ( _vm : & VirtualMachine , obj : PyObjectRef ) -> PyResult < Self > {
0 commit comments