3 ms·
FYI, you don't need to use the turbofish to hint `rustc` what time you need to `collect` here because it takes it from the return type: fn eval_forms(arg_f
by estebank 8y ago
FYI, you don't need to use the turbofish to hint `rustc` what time you need to `collect` here because it takes it from the return type:
fn eval_forms(arg_forms: &[RispExp], env: &mut RispEnv) -> Result<Vec<RispExp>, RispErr> {
arg_forms
.iter()
.map(|x| eval(x, env))
.collect()
}
You could also make the stylistic change (but not necessarily good change) of wrapping eval to make it less wordy:
fn eval_forms(arg_forms: &[RispExp], env: &mut RispEnv) -> Result<Vec<RispExp>, RispErr> {
let eval = |x| eval(x, env);
arg_forms
.iter()
.map(eval)
.collect()
}
At that point, it all fits in one line
fn eval_forms(arg_forms: &[RispExp], env: &mut RispEnv) -> Result<Vec<RispExp>, RispErr> {
let eval = |x| eval(x, env);
arg_forms.iter().map(eval).collect()
}
And you could make it so that you don't need to call `iter` inside of the fn on `arg_forms` and potentially accept many things besides slices:
fn eval_forms(
arg_forms: impl Iterator<Item=RispExp>,
env: &mut RispEnv,
) -> Result<Vec<RispExp>, RispErr> {
let eval = |x| eval(x, env);
arg_forms.map(eval).collect()
}
:)