Skip to content

Instantly share code, notes, and snippets.

@willmurphyscode
Created February 28, 2018 11:44
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/1e7f3c53df5a63e3f114fa804e7fab04 to your computer and use it in GitHub Desktop.
Save willmurphyscode/1e7f3c53df5a63e3f114fa804e7fab04 to your computer and use it in GitHub Desktop.
pub fn reduce_or(stack: &mut Vec<Token>) -> Result<Token, RuntimeError> {
// would return Err if the vector were not entirely
// made of Token::Operand(Type::Bool), since we can't reduce with `or`
// other values
let bool_result = unwrap_boolean_tokens(stack);
if let Ok(bool_vec) = bool_result {
Ok(Token::Operand(Type::Bool(
bool_vec.iter().any(|b| *b) // and reducer has "all" here
)))
} else {
Err(RuntimeError{ })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment