Use fold.
This commit is contained in:
@@ -1153,13 +1153,19 @@ impl Engine {
|
||||
));
|
||||
}
|
||||
|
||||
let (name, mut fn_curry) = arg.cast::<FnPtr>().take_data();
|
||||
let (name, fn_curry) = arg.cast::<FnPtr>().take_data();
|
||||
|
||||
// Append the new curried arguments to the existing list.
|
||||
a_expr.iter().skip(1).try_for_each(|expr| {
|
||||
self.get_arg_value(scope, mods, state, lib, this_ptr, level, expr, constants)
|
||||
.map(|(value, _)| fn_curry.push(value))
|
||||
})?;
|
||||
let fn_curry = a_expr.iter().skip(1).try_fold(
|
||||
fn_curry,
|
||||
|mut curried, expr| -> Result<_, Box<EvalAltResult>> {
|
||||
let (value, _) = self.get_arg_value(
|
||||
scope, mods, state, lib, this_ptr, level, expr, constants,
|
||||
)?;
|
||||
curried.push(value);
|
||||
Ok(curried)
|
||||
},
|
||||
)?;
|
||||
|
||||
return Ok(FnPtr::new_unchecked(name, fn_curry).into());
|
||||
}
|
||||
|
@@ -124,10 +124,7 @@ pub fn calc_fn_hash(fn_name: &str, num: usize) -> u64 {
|
||||
pub fn calc_fn_params_hash(params: impl Iterator<Item = TypeId>) -> u64 {
|
||||
let s = &mut get_hasher();
|
||||
let mut len = 0;
|
||||
params.for_each(|t| {
|
||||
len += 1;
|
||||
t.hash(s);
|
||||
});
|
||||
params.inspect(|_| len += 1).for_each(|t| t.hash(s));
|
||||
len.hash(s);
|
||||
s.finish()
|
||||
}
|
||||
|
Reference in New Issue
Block a user