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

Function filter

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

Source from the content-addressed store, hash-verified

221}
222
223fn filter(helper: &MyHelper, vs: Vec<IDLValue>, func: &str) -> Result<Vec<IDLValue>> {
224 let mut new_helper = helper.spawn();
225 let mut res = Vec::with_capacity(vs.len());
226 for v in vs.into_iter() {
227 new_helper.env.0.insert(String::new(), v.clone());
228 let arg = Exp::Path(String::new(), Vec::new());
229 let exp = Exp::Apply(func.to_string(), vec![arg]);
230 match exp.eval(&new_helper)? {
231 IDLValue::Bool(false) => (),
232 IDLValue::Bool(true) => res.push(v),
233 _ => return Err(anyhow!("filter function needs to return bool")),
234 }
235 }
236 Ok(res)
237}
238
239fn fold(helper: &MyHelper, init: Exp, vs: Vec<IDLValue>, func: &str) -> Result<IDLValue> {
240 let init = init.eval(helper)?;

Callers 1

projectFunction · 0.85

Calls 2

spawnMethod · 0.80
evalMethod · 0.80

Tested by

no test coverage detected