| 257 | } |
| 258 | |
| 259 | fn group_lte_op( |
| 260 | &self, |
| 261 | other: &Box<dyn Value>, |
| 262 | group_op: &GroupComparisonOperator, |
| 263 | ) -> Result<Box<dyn Value>, String> { |
| 264 | if other.is_array_of(|element_type| element_type.is_bool()) { |
| 265 | let elements = &other.as_array().unwrap(); |
| 266 | let mut matches_count = 0; |
| 267 | for element in elements.iter() { |
| 268 | if self.value <= element.as_bool().unwrap() { |
| 269 | matches_count += 1; |
| 270 | if GroupComparisonOperator::Any.eq(group_op) { |
| 271 | break; |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | let result = match group_op { |
| 277 | GroupComparisonOperator::All => matches_count == elements.len(), |
| 278 | GroupComparisonOperator::Any => matches_count > 0, |
| 279 | }; |
| 280 | |
| 281 | return Ok(Box::new(BoolValue::new(result))); |
| 282 | } |
| 283 | Err("Unexpected type to perform `<=` with".to_string()) |
| 284 | } |
| 285 | |
| 286 | fn not_op(&self) -> Result<Box<dyn Value>, String> { |
| 287 | Ok(Box::new(BoolValue::new(!self.value))) |