Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add map.reduce()
  • Loading branch information
gnsxun committed May 21, 2022
commit 09a10aaf270aee85f21f2df6e4006e9933d226b8
8 changes: 8 additions & 0 deletions vm/src/builtins/map.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::PyTypeRef;
use crate::{
builtins::PyTupleRef,
class::PyClassImpl,
function::PosArgs,
protocol::{PyIter, PyIterReturn},
Expand Down Expand Up @@ -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 {}
Expand Down