MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / call_zip

Method call_zip

compiler/src/modules/vm/builtins/sequence.rs:269–283  ·  view source on GitHub ↗

Pairs elements from N iterables into tuples, truncating to the shortest. */

(&mut self, op: u16)

Source from the content-addressed store, hash-verified

267
268 /* Pairs elements from N iterables into tuples, truncating to the shortest. */
269 pub fn call_zip(&mut self, op: u16) -> Result<(), VmErr> {
270 let mut iters: Vec<Vec<Val>> = Vec::with_capacity(op as usize);
271 let mut vals = Vec::with_capacity(op as usize);
272 for _ in 0..op { vals.push(self.pop()?); }
273 vals.reverse();
274 for v in vals { iters.push(self.extract_iter(v, false)?); }
275 let len = iters.iter().map(|v| v.len()).min().unwrap_or(0);
276 let mut pairs: Vec<Val> = Vec::with_capacity(len);
277 for i in 0..len {
278 let tuple: Vec<Val> = iters.iter().map(|v| v[i]).collect();
279 let t = self.heap.alloc(HeapObj::Tuple(tuple))?;
280 pairs.push(t);
281 }
282 self.alloc_and_push_list(pairs)
283 }
284
285 // TypeError for a non-iterable operand.
286 fn not_iterable(&self, o: Val) -> VmErr {

Callers 2

handle_functionMethod · 0.80
dispatch_nativeMethod · 0.80

Calls 8

pushMethod · 0.80
extract_iterMethod · 0.80
collectMethod · 0.80
alloc_and_push_listMethod · 0.80
popMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45
allocMethod · 0.45

Tested by

no test coverage detected