Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
fn reduce_subtraction(stack: &mut Vec<Token>) -> Result<Token, RuntimeError> {
let operands = unwrap_operand_tokens(stack);
match operands {
Ok(mut operand_vec) =>{
let initial_positive_option = operand_vec.pop();
if let Some(initial_positive) = initial_positive_option {
Ok(Token::Operand(
operand_vec
.iter()
.fold(initial_positive, |sum, value| sum - value)))
} else {
Err(RuntimeError{})
}
},
Err(_) => Err(RuntimeError{})
}
}
fn reduce_division(stack: &mut Vec<Token>) -> Result<Token, RuntimeError> {
let operands = unwrap_operand_tokens(stack);
match operands {
Ok(mut operand_vec) =>{
let initial_numerator_option = operand_vec.pop();
if let Some(initial_numerator) = initial_numerator_option {
Ok(Token::Operand(
operand_vec
.iter()
.fold(initial_numerator, |numerator, value| numerator / value)))
} else {
Err(RuntimeError{})
}
},
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.