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_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