Issue 1787 (#1827)

This commit is contained in:
Alexander James
2020-05-23 18:08:39 -06:00
committed by GitHub
parent 460daf029b
commit aadbcf5ce8
6 changed files with 227 additions and 10 deletions

View File

@ -198,9 +198,20 @@ pub fn evaluate(
}
pub fn sum(data: Vec<Value>) -> Result<Value, ShellError> {
Ok(data
.into_iter()
.fold(Value::zero(), |acc: Value, value| acc + value))
let mut acc = Value::zero();
for value in data {
match value.value {
UntaggedValue::Primitive(_) => acc = acc + value,
_ => {
return Err(ShellError::labeled_error(
"Attempted to compute the sum of a value that cannot be summed.",
"value appears here",
value.tag.span,
))
}
}
}
Ok(acc)
}
fn formula(