Skip to content

Commit 09a10aa

Browse files
author
gnsxun
committed
Add map.reduce()
1 parent b289aa5 commit 09a10aa

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

vm/src/builtins/map.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::PyTypeRef;
22
use crate::{
3+
builtins::PyTupleRef,
34
class::PyClassImpl,
45
function::PosArgs,
56
protocol::{PyIter, PyIterReturn},
@@ -45,6 +46,13 @@ impl PyMap {
4546
Ok(max)
4647
})
4748
}
49+
50+
#[pymethod(magic)]
51+
fn reduce(&self, vm: &VirtualMachine) -> (PyTypeRef, PyTupleRef) {
52+
let mut vec = vec![self.mapper.clone()];
53+
vec.extend(self.iterators.iter().map(|o| o.clone().into()));
54+
(vm.ctx.types.map_type.clone(), vm.new_tuple(vec))
55+
}
4856
}
4957

5058
impl IterNextIterable for PyMap {}

0 commit comments

Comments
 (0)