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

Method iter_cursor

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

Build an IterCursor so short-circuit builtins (e.g. `all(range(10**6))`) stop at the first hit instead of pre-materialising. TypeError on non-iterables. */

(&self, o: Val)

Source from the content-addressed store, hash-verified

289
290 /* Build an IterCursor so short-circuit builtins (e.g. `all(range(10**6))`) stop at the first hit instead of pre-materialising. TypeError on non-iterables. */
291 pub(in crate::modules::vm) fn iter_cursor(&self, o: Val) -> Result<IterCursor, VmErr> {
292 if !o.is_heap() {
293 return Err(self.not_iterable(o));
294 }
295 Ok(match self.heap.get(o) {
296 HeapObj::Range(s, e, st) => IterCursor::Range { cur: *s, end: *e, step: *st },
297 HeapObj::Bytes(b) => IterCursor::Bytes { bytes: b.clone(), idx: 0 }, // Vec<u8> clone
298 HeapObj::Str(s) => IterCursor::StrChars { chars: s.chars().collect(), idx: 0 },
299 HeapObj::List(v) => IterCursor::Vec { items: v.borrow().clone(), idx: 0 },
300 HeapObj::Tuple(v) => IterCursor::Vec { items: v.clone(), idx: 0 },
301 HeapObj::Set(v) => IterCursor::Vec { items: v.borrow().iter().cloned().collect(), idx: 0 },
302 HeapObj::FrozenSet(v) => IterCursor::Vec { items: v.iter().cloned().collect(), idx: 0 },
303 HeapObj::Dict(d) => IterCursor::Vec { items: d.borrow().keys().collect(), idx: 0 },
304 _ => return Err(self.not_iterable(o)),
305 })
306 }
307
308 /* Vec<Val> from any iterable (dict yields keys, str yields one-char strs, bytes yields ints). `include_range = false` lets callers reject Range. */
309 pub(in crate::modules::vm) fn extract_iter(&mut self, o: Val, include_range: bool) -> Result<Vec<Val>, VmErr> {

Callers 3

call_sumMethod · 0.80
call_allMethod · 0.80
call_anyMethod · 0.80

Calls 7

is_heapMethod · 0.80
not_iterableMethod · 0.80
collectMethod · 0.80
borrowMethod · 0.80
keysMethod · 0.80
getMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected