| 221 | } |
| 222 | |
| 223 | fn 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 | |
| 239 | fn fold(helper: &MyHelper, init: Exp, vs: Vec<IDLValue>, func: &str) -> Result<IDLValue> { |
| 240 | let init = init.eval(helper)?; |