Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@willmurphyscode
Last active January 30, 2018 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willmurphyscode/bec5200077ea2cc53a54dff0e6a0441e to your computer and use it in GitHub Desktop.
Save willmurphyscode/bec5200077ea2cc53a54dff0e6a0441e to your computer and use it in GitHub Desktop.
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