MCPcopy Create free account
hub / github.com/dfinity/ic-repl / fold

Function fold

src/selector.rs:239–252  ·  view source on GitHub ↗
(helper: &MyHelper, init: Exp, vs: Vec<IDLValue>, func: &str)

Source from the content-addressed store, hash-verified

237}
238
239fn fold(helper: &MyHelper, init: Exp, vs: Vec<IDLValue>, func: &str) -> Result<IDLValue> {
240 let init = init.eval(helper)?;
241 let mut new_helper = helper.spawn();
242 let mut acc = init;
243 for v in vs.into_iter() {
244 new_helper.env.0.insert(String::new(), v);
245 let arg = Exp::Path(String::new(), Vec::new());
246 new_helper.env.0.insert("_".to_string(), acc.clone());
247 let accu = Exp::Path("_".to_string(), Vec::new());
248 let exp = Exp::Apply(func.to_string(), vec![accu, arg]);
249 acc = exp.eval(&new_helper)?;
250 }
251 Ok(acc)
252}

Callers 1

projectFunction · 0.85

Calls 2

evalMethod · 0.80
spawnMethod · 0.80

Tested by

no test coverage detected