Last active
January 30, 2018 11:55
-
-
Save willmurphyscode/bec5200077ea2cc53a54dff0e6a0441e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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