Add map.reduce()
use super::PyTypeRef;
use crate::{
+ builtins::PyTupleRef,
class::PyClassImpl,
function::PosArgs,
protocol::{PyIter, PyIterReturn},
@@ -45,6 +46,13 @@ impl PyMap {
Ok(max)
})
}
+
+ #[pymethod(magic)]
+ fn reduce(&self, vm: &VirtualMachine) -> (PyTypeRef, PyTupleRef) {
+ let mut vec = vec![self.mapper.clone()];
+ vec.extend(self.iterators.iter().map(|o| o.clone().into()));
+ (vm.ctx.types.map_type.clone(), vm.new_tuple(vec))
+ }
}
impl IterNextIterable for PyMap {}
