MCPcopy Create free account
hub / github.com/argumentcomputer/ix / decode_assoc_list

Function decode_assoc_list

crates/ffi/src/ix/env.rs:73–99  ·  view source on GitHub ↗

Decode a HashMap's AssocList and collect key-value pairs using a custom decoder.

(
  obj: LeanBorrowed<'_>,
  decode_key: FK,
  decode_val: FV,
)

Source from the content-addressed store, hash-verified

71
72/// Decode a HashMap's AssocList and collect key-value pairs using a custom decoder.
73fn decode_assoc_list<K, V, FK, FV>(
74 obj: LeanBorrowed<'_>,
75 decode_key: FK,
76 decode_val: FV,
77) -> Vec<(K, V)>
78where
79 FK: Fn(LeanBorrowed<'_>) -> K,
80 FV: Fn(LeanBorrowed<'_>) -> V,
81{
82 let mut result = Vec::new();
83 let mut current = obj;
84
85 while !current.is_scalar() {
86 let ctor = current.as_ctor();
87 if ctor.tag() == 0 {
88 break; // AssocList.nil
89 }
90 // AssocList.cons: 3 fields (key, value, tail)
91 let key = ctor.get(0);
92 let val = ctor.get(1);
93 let next = ctor.get(2).as_raw();
94 result.push((decode_key(key), decode_val(val)));
95 current = unsafe { LeanBorrowed::from_raw(next) };
96 }
97
98 result
99}
100
101/// Decode a Lean HashMap into a Vec of key-value pairs.
102/// HashMap structure (after unboxing): Raw { size : Nat, buckets : Array (AssocList α β) }

Callers 1

decode_hashmapFunction · 0.85

Calls 3

tagMethod · 0.80
pushMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected