Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
fn reduce_addition(stack: &mut Vec<Token>) -> Result<Token, RuntimeError> {
let operands = unwrap_operand_tokens(stack);
match operands {
Ok(operand_vec) => Ok(Token::Operand(
operand_vec
.iter()
.fold(0, |sum, value| sum + value))),
Err(_) => Err(RuntimeError{})
}
}
fn reduce_multiplication(stack: &mut Vec<Token>) -> Result<Token, RuntimeError> {
let operands = unwrap_operand_tokens(stack);
match operands {
Ok(operand_vec) => Ok(Token::Operand(
operand_vec
.iter()
.fold(1, |prod, value| prod * value))),
Err(_) => Err(RuntimeError{})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.