Created
January 31, 2018 11:30
-
-
Save willmurphyscode/71074de7a8f544ddd27ebec4b3f287dd 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_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